I loop over string variable data
which may have integer numeric value, like "123"
. If this string variable has numeric value, I want to indicate it and thought to use some like this:
If IsNumeric(CInt(data)) Then
WScript.Echo "Number"
Else
WScript.Echo "String"
End If
But CInt()
raises error every time data
variable can't be converted to integer:
Type mismatch: 'CInt'
How can I indicate if string has integer value in vbscript?
IsNumeric Function of vb script can be used to determine whether an expression can be evaluated as a number.It returns Boolean value depending upon expression
Please be noted that IsNumeric returns False if expression is a date expression.
Now, in your code you have mistaken that even if it is not number, you trying to convert it into integer
You can use this in your code like this--
If IsNumeric(data) Then
WScript.Echo "Number"
Else
WScript.Echo "String"
End If
only for integers:
If VarType(data) = vbInteger Then
WScript.Echo "Integer"
Else
WScript.Echo "Something else"
End If
for numbers:
If IsNumeric(data)
WScript.Echo "Number"
Else
WScript.Echo "string"
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With