Checking Data Type in VB.Net
How would i check if a text box's text is an inter ger , and if it is not an integer , than how can i get it to tell me this
i need this type
if textbox1.text = integer then
Messagebox.show ( " this is an integer")
else
Messagebox.show("This isnt an integer")
end if
Obviously this does not work.
You could use Int32.TryParse(), like this:
Dim OutVal As IntegerIf Integer.TryParse(TextBox1.Text, OutVal) Then MessageBox.Show(String.Format("This is an integer, and its value is {0}.", OutVal))Else MessageBox.Show("This isn't an integer.")End If
Moved to For Beginners. Pyromaniac, please make an effort to start your threads in the right forum to begin with.
Module Module1 Sub Main() If GetType(Integer) Is GetType(Char) Then Console.WriteLine("1. An integer is an integer") End If If GetType(Integer) Is GetType(Integer) Then Console.WriteLine("2. An integer is an integer") End If Dim x As Integer If x.GetType() Is GetType(Integer) Then Console.WriteLine("3. An integer is an integer") End If End SubEnd Module
Thank you very much for you replies, they are a great help.
Btw , i will try to Put my posts in the right section next time.
What the program was , was a temperature conversion program, i needed the input to be an integer, then it would be passed and depending on which rdio button as checked it would convert it into that type. Any other methods, i want to know many.
Btw , i will try to Put my posts in the right section next time.
What the program was , was a temperature conversion program, i needed the input to be an integer, then it would be passed and depending on which rdio button as checked it would convert it into that type. Any other methods, i want to know many.
Btw, I found what i was looking for myself, If anyone want to know , it was the builtin "IsNumeric" Keyword .
If IsNumeric(Textbox1.text) then
Do stuff
End if
If IsNumeric(Textbox1.text) then
Do stuff
End if
I have a natural aversion to VB's built-in functions, as they are non-portable between other .NET-friendly languages. [smile]
Bear in mind that IsNumeric doesn't check for integers; it will also handle floating-point values.
Bear in mind that IsNumeric doesn't check for integers; it will also handle floating-point values.
Quote:Original post by pyromaniac4382
what exactly is 'IsNumeric' checking for then?
Things that are, well, numeric. As in, interpretable as some kind of number. (Or at least, one of the types of number that's built into the language. Some mathematicians seem to make a hobby of inventing new kinds of numbers ;) )
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement