|
-
Oct 31st, 2001, 01:15 PM
#1
Val function and percent symbol
Example:
Val("1.6%") returns a type mismatch error. Why?
the decimal is valid within Val()
shouldn't this return 1.6 ?
anyone?
-
Oct 31st, 2001, 01:17 PM
#2
-
Oct 31st, 2001, 01:44 PM
#3
the whole purpose of Val () is
to lose the percent sign for me....
anyone....except hack?
-
Oct 31st, 2001, 01:52 PM
#4
PowerPoster
Why are you using the Val() function anyway? The value of 1.6 is 1.6 =p
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Oct 31st, 2001, 02:31 PM
#5
PowerPoster
Well
Use the tag propery to store the number. Then use val on that number, not the one displayed to the user...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Nov 1st, 2001, 10:18 AM
#6
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
-
Nov 1st, 2001, 10:33 AM
#7
Originally posted by larryn
Anyway.....
I wrote my own Val () function which I think
is better than the original...
too bad it doesn't work on "-123.456"
-Lou
-
Nov 1st, 2001, 10:51 AM
#8
just put a negative sign into the VALID constant..
"1234567890-."
that wasn't so hard was it...?
-
Nov 1st, 2001, 10:53 AM
#9
PowerPoster
Well
If you add the " . - ", this will let me type multiple of these keys and thus create a non-numeric entry correct?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|