I have written a code that displays 6 DataGridView tables with values from excel that contain exchange rates for euros and us dollars from 6 different banks. The exchange rates are imported from excel file. Now i have to compare each of them and display the min value for euro buy rate (Куповен курс) and max value for sell rate (Продажен/Откупен курс) and min value for dollar buy rate (Куповен курс) and max value for sell rate (Продажен/Откупен курс). I need some help with C# code that will compare those values and display them in a TextBox by clicking the Compare button.
Here is pic from my app:
http://uploadpic.org/v.php?img=CYRmqhbE6F
I tried with this code, but give me error:
private void button7_Click(object sender, EventArgs e)
{
string s = dataGridView1.Rows[1].Cells[1].Value.ToString();
string t = dataGridView2.Rows[0].Cells[6].Value.ToString();
string k = dataGridView3.Rows[0].Cells[1].Value.ToString();
string l = dataGridView4.Rows[0].Cells[4].Value.ToString();
string m = dataGridView5.Rows[0].Cells[2].Value.ToString();
string n = dataGridView6.Rows[0].Cells[3].Value.ToString();
string[] kupoven = new string[] { s,t,k,l,m,n};
int length = kupoven.Length;
int last = length - 1;
int largest = kupoven[];
for (int i = 1; i <= length / 2; i++)
{
if (kupoven[i] > kupoven[last] && kupoven[i] > largest) largest = arr[i];
else if (kupoven[last] > largest) largest = kupoven[last];
last--;
}
return largest;
}
With this i put all euro values in strings(s,t,k,l,m,n), then i put them in array, and then i try to get the max value from the array. I think the problem is with type string.
That code you posted most likely doesn’t compile… you should always post code that compiles, unless your question is about code that’s not compiling. I would strongly recommend that you try to post sscce compliant questions: http://sscce.org/
With that said, if you want the maximum value I would do something along the lines:
Of course, that would only be store the maximum value in the local variable max. To display the max in a text box you would have to write some more code. I also feel like that simply displaying the maximum value may not be sufficient, given that you’re comparing the exchange rate between different banks.