• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How do I detect a numberic data type from a string in VB.net

seanp789

Senior member
Lets say I have a textbox1.Text

without using a masked textbox how do I check the string to see if it is numeric or not?

I can not use a try catch to catch a casting error.

I have to use IF or Select statements to detect the error.

 
Originally posted by: WannaFly
It has a flaw, but I cannot remember what it is right now.

This is what I found in another forum.

ReturnValue = IsNumeric("($1,23,,3.4,,,5,,E67$)")

Most people would not expect THAT to return True. IsNumeric has some "flaws"
in what it considers a proper number and what most programmers are looking
for.

......

Basically, it said that IsNumeric returned True for things like -- currency symbols being
located in front or in back of the number as shown in my example (also
applies to plus, minus and blanks too); numbers surrounded by parentheses as
shown in my example (some people use these to mark negative numbers);
numbers containing any number of commas before a decimal point as shown in
my example; numbers in scientific notation (a number followed by an upper or
lower case "D" or "E", followed by a number equal to or less than 305 -- the
maximum power of 10 in VB); and Octal/Hexadecimal numbers (&H for
Hexadecimal, &O or just & in front of the number for Octal)
 
Yup that appears to be exactly what I was looking for, thanks guys. I saw that method before but wasnt quite sure how it should be used. Even though it has flaws I just tested the example program the professor gave us and it has the same flaws so that is probably what he used.

Il keep those flaws in mind though if I ever have to use it commercially.
 
Back
Top