Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
basically I am Visual FoxPro Programmer shifting my complete application into C# visual Studio 2019
i am fixed between variables
i am trying to get value from a variable into variable
please help me out
please try that variables value and type should not be changed.

What I have tried:

C#
string cust_name = "Kishor";
int tot_amt = 100;
int adl_amt = 50;
int tax_amt = 18;

string col1 = "cust_name";
string col2 = "tot_amt+adl_amt+tax_amt";

Console.WriteLine(col1);
Console.WriteLine(col2);
Posted
Updated 11-May-20 8:43am
v2
Comments
Kishore_Patel 11-May-20 14:41pm    
values for col1 and col2 are transferred from table report

Do not put variable names in quotes, use this:
string col1 = cust_name;
string col2 = (tot_amt + adl_amt + tax_amt).ToString();
 
Share this answer
 
Simple:
C#
string col1 = cust_name; // Remove the quotes
int col2 = tot_amt + adl_amt + tax_amt; // Remove the quotes, and fix the variable type

Console.WriteLine(col1);
Console.WriteLine(col2);
 
Share this answer
 
By wrapping the declarations for col1/col2 within quotes; you are making them strings of the content inside.
Furthermore, col2 is made up of a numeric function; and needs to be converted to a string. Try these replacements out
C#
string col1 = cust_name;
string col2 = (tot_amt + adl_amt + tax_amt).ToString();

Console.WriteLine(col1);
Console.WriteLine(col2);
If you wanted to create a Class for this (eg Customer), you could do it similar to this
C#
public class Customer {
	public string cust_name { get; set; }
	public int tot_amt { get; set; }
	public int adl_amt { get; set; }
	public int tax_amt { get; set; }

	public Customer() {} // construct

	public string col1 { get { return cust_name; }}
	public string col2 = {get {return (tot_amt+adl_amt+tax_amt).ToString(); }}
}
public cust = new Customer();
cust.cust_name = "Kishor";
cust.tot_amt = 100;
cust.adl_amt = 50;
cust.tax_amt = 18;

Console.WriteLine(col1);
Console.WriteLine(col2);
Or you could also create one with an overloaded construct like this to simplify the usage
C#
public class Customer {
	public string cust_name { get; set; }
	public int tot_amt { get; set; }
	public int adl_amt { get; set; }
	public int tax_amt { get; set; }

	public Customer() {}
	public Customer(string nameCust, int amtTot, int amtAdl, int amtTax) {
		cust_name = nameCust;
		tot_amt = amtTot;
		adl_amt = amtAdl;
		tax_amt = amtTax;
	}

	public string col1 { get { return cust_name; }}
	public string col2 = {get {return (tot_amt+adl_amt+tax_amt).ToString(); }}
}

public cust = new Customer("Kishor", 100, 50, 18);

Console.WriteLine(col1);
Console.WriteLine(col2);
 
Share this answer
 
v2
Comments
Kishore_Patel 11-May-20 14:57pm    
Thanks I am near to solution.
basic problem was I have 2 tables
1. sales with (cust_name, tot_amt, adl_amt, tax_amt)
2. report with (col1, col2, ….)
I have to read col1 col2... from report file where col1 col2 can have fields of sales table
so read the fields from report file and get that field values from sales table and print them or set to datagrid

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900