Click to See Complete Forum and Search --> : Convert string


vchapran
March 23rd, 2001, 10:19 AM
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

Clearcode
March 23rd, 2001, 10:49 AM
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

vchapran
March 23rd, 2001, 10:56 AM
Just try this function with deleted first digit, i.e ",000.00".

Clearcode
March 23rd, 2001, 11:05 AM
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

vchapran
March 23rd, 2001, 11:17 AM
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