How do I convert a string to a double

srmousse

Registered User.
Local time
Yesterday, 21:07
Joined
Jun 27, 2005
Messages
16
I am trying to convert a string absolutely contains a number at all times to a double for use of comparison and numerical calculation, VBA doesn't seem to support the System.Convert.ToDouble() method... I have searched and searched and can't find a way to do this... any help would be VERY appreciated!

For a little extra info (for anyone who wants to know) the number stored in the text field is a four digit number with no decimal or anything else fancy like that. I would not hesitate converting it to a different number if it were easier.
 
edit directly

Apparently I can manipulate the string as a number directly... hmm... that is interesting, but is it safe?
 
From testing it all looks good.

If the string is a valid number (no characters in it other than numbers) you can directly set a double equal to it. Otherwise I would suggest using an algorithm working from right to left of the string... if you need help I can help you on this.
 
Last edited:
Thanks!

Thanks, I appreciate the offer!!! I think it will be okay, I have an input mask on that particular field forcing the value to be 4 charicters of numerical value only, so I don't think there will be a chance of it being anything but numerical.
 
VBA doesn't seem to support the System.Convert.ToDouble() method

Use CDbl(expression)

4 charicters of numerical value only
Then it is only an iteger realy so you could use
CInt(expression)

But why not just convert it to a number datatype in the table rather than use a string?

Peter

PS. you can use IsNumeric() to test if it is a number
 
Last edited:
srmousse said:
VBA doesn't seem to support the System.Convert.ToDouble() method.

That's because System.Convert.ToDouble() is Visual Basic.NET and VBA is not Visual Basic.NET. :)
 

Users who are viewing this thread

Back
Top Bottom