Checking if variable is number

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Fred
Newbie
Posts: 18
Joined: Sat Aug 05, 2017 4:44 pm

Checking if variable is number

Post by Fred » Tue Aug 15, 2017 3:14 pm

I am taking my data from a website by mouseclicking in the predefined region and copying the number to clipboard. Usually this works perfect, but sometimes during the site refresh doubleclicking and copying to clipboard either take no data, or take non numeral data (some kind of text near my needed number). After this my conditional formulas do not work and I receive the message like this:

Image

After this the program stops till I press OK, but continues to work after pressing. This is no problem for me if sometimes this happens, but problem, if the program stops.

Can I check if the variable is number? I can check if the variable is assigned by "Assigned", but if my mouseclick take text data, the Assigned function give TRUE, and the script continues and stops on IF condition when comparing the variable with number.

Also, maybe there is some way to prevent from these messages to appearing and the script from stopping? There is no problem if one iteration of my script is bad, the next one will surely take good data, and the program will run correctly.

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

Re: Checking if variable is number

Post by JRL » Tue Aug 15, 2017 4:16 pm

Search the forum for isnumeric

Fred
Newbie
Posts: 18
Joined: Sat Aug 05, 2017 4:44 pm

Re: Checking if variable is number

Post by Fred » Sun Sep 17, 2017 6:54 pm

Still unable to resolve this. Maybe there are functions that force the script to restart is such an message or error appeared? It looks, by pressing OK it continues to run even if there is wrong data or no data, and on second iteration it surely get the right data.
So, can I force my script to restart if this happened? Or force not to stop and give me a message?

User avatar
Grovkillen
Automation Wizard
Posts: 1023
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Checking if variable is number

Post by Grovkillen » Mon Sep 18, 2017 7:55 am

A simple %value%/%value% is a way to do it.

Code: Select all

Input>value,Type value,0
If>value=0
  Let>CheckValue=1
Else>
  Let>CheckValue=%value%/%value%
Endif>
If>CheckValue=1
  MDL>Value is a number!
Else>
  MDL>Value is NOT a number!
Endif
Last edited by Grovkillen on Tue Sep 19, 2017 6:52 am, edited 1 time in total.
Let>ME=%Script%

Running: 15.0.24
version history

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

Re: Checking if variable is number

Post by JRL » Mon Sep 18, 2017 5:19 pm

Or force not to stop and give me a message?
Add the line:
Let>ignoreerrors=1
Somewhere ahead of where your error occurs.

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Checking if variable is number

Post by PepsiHog » Tue Sep 19, 2017 3:08 pm

Isnumeric

or

I use regex to check the first character is a number. If not a number, then try again.

You could even invalidate the result if it is not only a number.

RegEx>\b(\d).*,0,match,res,1,$1,ResVar

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

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