I am using the IsNumeric() function in visual basic 2012.
my code is this
Dim input As String = "123"
If isNumeric(input) Then
'not a number codes
isNumeric is a namespace and cannot be used as an expression
It sounds like you've created a name clash. You have presumably named your project 'IsNumeric'. The root namespace for the project is named after the project by default so you now have a root namespace named 'IsNumeric' and that takes precedence over the
There are a number of options to fix this. Firstly, you can change the root namespace for the project to something other than 'IsNumeric', which you would do in the project properties. Alternatively, you can qualify the method name with its namespace, its module or both, i.e. use
I'd tend to suggest not using IsNumeric anyway. It can't distinguish between types of numbers and provides no access to the actual numeric value. If you need to do any of that sort of thing then call the appropriate
TryParse method instead, e.g.
Dim number As Double If Double.TryParse(someText, number) Then 'The input was a valid Double and the value is in 'number'. Else 'The input was not a valid Double. End If
IsNumeric actually calls
Double.TryParse internally and is the reason it was created in the first place. That's why calling
IsNumeric and then something like
CDbl is bad: you're parsing the same text twice in that case.