Input string not in correct format...

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) + ";"
 
A

Alexey Smirnov

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?
 
G

Garg

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
 
A

Alexey Smirnov

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()

?
 
G

Garg

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.
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top