converting a string to an integer or integer to string

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
krillin47
Newbie
Posts: 1
Joined: Fri Feb 09, 2007 5:49 am

converting a string to an integer or integer to string

Post by krillin47 » Fri Feb 09, 2007 5:52 am

I need help to convert a string to an integer or the other way around. I'm trying to use an IF> statement to evaluate the data I have in a text file to something it grabs from the clipboard to compare. It always fails to compare the two and tell me when it has found a match.

Any help would be apprieciated.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Feb 09, 2007 8:44 am

Actually you don't need to convert numbers to strings or strings to numbers - Macro Scheduler can do that automatically. As long as a string can be interpreted as a number you do not need to do any conversion.

If your comparison fails then it may be that there are spaces or other invisible characters before or after your string.

E.g. "2.5" is numeric, but " 2.5 " is not.

So you could try the following after reading from the file:

VBSTART
VBEND
StringReplace>ValueFromFile,CR,,ValueFromFile
StringReplace>ValueFromFile,LF,,ValueFromFile
StringReplace>ValueFromFile,","",ValueFromFile
VBEval>Trim("%ValueFromFile%"),ValueFromFile

That will remove any carriage returns, line feeds and spaces from the value returned. If a pure number is all that is left then you can now use the numerical comparisons, or mathematical functions.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts