Example:
Val("1.6%") returns a type mismatch error. Why?
the decimal is valid within Val()
shouldn't this return 1.6 ?
anyone?
Printable View
Example:
Val("1.6%") returns a type mismatch error. Why?
the decimal is valid within Val()
shouldn't this return 1.6 ?
anyone?
Lose the % sign.
to lose the percent sign for me....
anyone....except hack?
Why are you using the Val() function anyway? The value of 1.6 is 1.6 =p
Use the tag propery to store the number. Then use val on that number, not the one displayed to the user...
Hack, you are correct to a degree, but you left
out one important point - which is this:
The Val () function is designed to return the numbers
contained in a string as a numeric value of appropriate type.
When it reaches a non-numeric it is supposed to stop
reading the string.
So if i have a string value such as "1.6%" in an excel
spreadsheet cell, and extract that data minus the %
sign, i should be able to use Val () to do it...
Anyway.....
I wrote my own Val () function which I think
is better than the original...
here it is:
Code:Public Function Val2(sString As String) As Double
Dim sTemp As String
Dim sOut As String
Dim iX As Long
Const VALID = "1234567890."
For iX = 1 To Len(sString)
sTemp = Mid$(sString, iX, 1)
If InStr(VALID, sTemp) <> 0 Then
sOut = sOut & sTemp
End If
Next
Val2 = sOut
End Function
too bad it doesn't work on "-123.456"Quote:
Originally posted by larryn
Anyway.....
I wrote my own Val () function which I think
is better than the original...
:(
-Lou
just put a negative sign into the VALID constant..
"1234567890-."
that wasn't so hard was it...?
If you add the " . - ", this will let me type multiple of these keys and thus create a non-numeric entry correct?