|
-
March 23rd, 2001, 11:19 AM
#1
Convert string
Although it's very easy to write my own function to convert the string, presented by digits, commas and dots to Long, I would ask, maybe somebody knows good source of string manipulation functions. I just do not want to invent bycicle.
Thank you.
Vlad
-
March 23rd, 2001, 11:49 AM
#2
Re: Convert string
You could use the VB command CLng thus:
Dim lVal
lVal = CLng("1,000.00")
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
-
March 23rd, 2001, 11:56 AM
#3
Re: Convert string
Just try this function with deleted first digit, i.e ",000.00".
-
March 23rd, 2001, 12:05 PM
#4
Re: Convert string
yes - but that isn't a meaningful number.
To extract the number portion of a string:
'\\ --[IntlAwareVal]--------------------------------------------------
'\\ The Val function is not internationally aware, but provides more
'\\ functionality than the internationally aware "CDbl" so this
'\\ is a replacement for both
'\\ ----------------------------------------------------------------------
public Function IntlAwareVal(byval sIn as string) as Double
'\\ Add a zero at the front to cope with empty strings
If IsNumeric("0" & Trim$(sIn)) then
sIn = "0" & Trim$(sIn)
End If
If IsNumeric(Trim$(sIn)) then
IntlAwareVal = CDbl(Trim$(sIn))
else
IntlAwareVal = Val(Trim$(sIn))
End If
End Function
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
-
March 23rd, 2001, 12:17 PM
#5
Re: Convert string
Yes, comma is not a meaningful character, but imagine a situation, when project contains thousands of input controls (Textboxes, combos and so on), almost all have some kind of validation, data is formatted either while user enters it or after control loses its focus. So far everything was OK, today somebody tried to delete first digit from 2,222.00. Run Time error occured, because that value was going to be converted with CDbl. So, I'd like to see already created by somebody string manipulation functions in order to select some of them for this project, or at least to find out, what kind of conversion is sometime required.
Vlad
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
|