Input string not in correct format...

  • Thread starter Thread starter Garg
  • Start date Start date
G

Garg

Everytime I run my code, it shows an error that the input string is
not in correct format.
Could anybody tell me what is wrong with my line of code?

str3 = Integer.Parse(dropBasis3.SelectedIndex - 1, 10) + ";"
 
Everytime I run my code, it shows an error that the input string is
not in correct format.
Could anybody tell me what is wrong with my line of code?

str3 = Integer.Parse(dropBasis3.SelectedIndex - 1, 10) + ";"

I suppose that dropBasis3.SelectedIndex - 1 is an integer?
Integer.Parse needs a string.

What does ", 10" means?
 
10 represents the system in which we want our integer answer.
So, here 10 stands for decimal system.
If we had wanted our answer in binary sytem, then instead of 10. it
would have been 2
 
10 represents the system in which we want our integer answer.
So, here 10 stands for decimal system.
If we had wanted our answer in binary sytem, then instead of 10. it
would have been 2

well, ok, I didn't know it, thanks

Back to your problem - what do you want to parse from integer???

Maybe you wanted to have

dropBasis3.Items(dropBasis3.SelectedIndex - 1).ToString()

?
 
well, ok, I didn't know it, thanks

Back to your problem - what do you want to parse from integer???

Maybe you wanted to have

dropBasis3.Items(dropBasis3.SelectedIndex - 1).ToString()

?

thats alrite..
I've removed that integer.parse function from there. I realised it
wan't needed at all there. so, no problems now in my code.
 
Hi Garg

This is not javascript. In .NET Integer.Parse(string, flags) flags parameter
has quite different meaning - it determines the styles permitted in numeric
string arguments that are passed to the Parse methods of the numeric base
type classes. Please read MSDN documentation before using a function/method.

Best regards
 
Garg,

dropBasis3.SelectedIndex is already a integer value. I quess you come from
javascript /vbscript programming (correct me if i'm wrong) you are trying to
execute equivalent code
var x = parseInt(whatever, 10).
Forget it.

vb.net:
dim str3 as string = Convert.ToString(dropBasis3.SelectedIndex - 1) & ";"
c#:
string str3 = Convert.ToString(dropBasis3.SelectedIndex - 1) + ";"

Or maybe if i didn't get you right, you're trying to parse drop down list
selected value:

vb.net:
Dim result As Integer
Dim str3 As String = IIf(Integer.TryParse(dropBasis3.SelectedValue ,
result), result, 0) & ";"
c#:
int result;
string str3 = int.TryParse(dropBasis3.SelectedValue, out result) ?
result.ToString() : "0";
str3 += ";";

hope this helps
 
Back
Top