This is my code:
Dim strsample, x
strsample = label.text
x = strsample + 1
Error :Input string was not in a correct format.
Please help to convert label.text to integer
Thanks in advance
Hmm... have you tried this: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=163
jpgjuan:This is my code: Dim strsample, x strsample = label.text x = strsample + 1 Error :Input string was not in a correct format. Please help to convert label.text to integer Thanks in advance
strsample = Val(label.text)
Convert limitations to great expectations... You are the creative force of your life...
You need to convert the value of label.Text to an numeric value first before you can use it in any mathematical expression.
Use Convert.Int32 method to accomplish what you wanted
http://msdn.microsoft.com/en-us/library/sf1aw27b.aspx
Hehehe, I'll do it in C#
string lblTextBox1;
int x, y;
lblTextBox1 = Label1.text;
try {
x = int.Parse(lblTextBox1);
} catch {
throw new Exception("duh, whatever");
}
y = x +1;
why not use the Int32.TryParse() or Int64.TryParse() methods? no need to catch for exceptions.
I agree with cruizer. Using Convert.ToInt32() causes exceptions when trying to convert non numerical format and decimal inputs. TryParse since it returns a boolean value can work around these exceptions.