How to check if variable contains a number

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
billtubbs
Junior Coder
Posts: 32
Joined: Thu Dec 07, 2006 10:00 pm
Location: Vancouver
Contact:

How to check if variable contains a number

Post by billtubbs » Thu Mar 15, 2007 9:25 pm

Hi

I am writing a macro that reads data from a text file using the Readln> command. Occasionally the text file will contain a line with only one number on it.

When this happens the variable that is assigned the line of text becomes numeric and seems to have different properties.

For example the following statement breaks down when the variable contains only a number:

Code: Select all

Until>line,##EOF##
This works fine until line contains 123.4 for example. Then it reports three error messages: 'Syntax Error', then 'Error Parsing Expression', followed by '# not appropriate'.

Fortunately you can get round this because the if> command is not vulnerable to this problem.

e.g.

Code: Select all

If>line=##EOF##,finish
always works.

However, I still would like to test that my variable line contains a valid number after the Readln command. What's the easiest way to do this?

Bill.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Mar 15, 2007 9:32 pm

Hi Bill,

Several methods for testing to see if a value is numeric are discussed here.

Hope this helps,
Dick

billtubbs
Junior Coder
Posts: 32
Joined: Thu Dec 07, 2006 10:00 pm
Location: Vancouver
Contact:

Testing if numeric - problem solved

Post by billtubbs » Thu Mar 15, 2007 10:44 pm

Of course, do it in VBScript. Should have thought of that.
thanks
Bill.

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