Check if variable is numeric

Discuss RoboTask here
Post Reply
sarnusch
Posts: 35
Joined: Thu Apr 28, 2022 9:05 am

Check if variable is numeric

Post by sarnusch »

Hi,
Because I want to save edited images automatically into another folder, the source file name (e.g. 1234567.jpg or 1234567_v1.jpg) must be checked.
The file name must be numeric with the exception of the letter 'v' (for 'version') and the special charater '_' and must not contain any other letters or special characters.
I did not find a possibility to check this in a smart way.
Is there a solution to do this with RoboTask?
Kind regards,
Sebastian
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Check if variable is numeric

Post by Oleg »

You can use regular expression to check name
Expression is:

Code: Select all

(?i)^(\d+|\d+_v\d+)\.jpg$
Also look at complete example (look at the step #3)

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1468"
Hide=INTEGER|0
ID=INTEGER|-1708117588
LogOnAsUser=INTEGER|1
Name=STRING|"check file name"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|2
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""Names"" File names list"
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"Names"
varvalue=STRING|"1234567.jpg{EOL}1234567_v1.jpg{EOL}1234567_v5.jpg{EOL}DSC_1746.jpg"

[Actions\Action2]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action2\Params]
destvar=STRING|"LINE"
line0=STRING|"{Names}"
linecount=STRING|"1"
sourcetext=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_REGEXP_MATCH"
Enabled=INTEGER|-1
Name=STRING|"RegExp Match"
Params=FOLDER

[Actions\Action3\Params]
anchored=STRING|"0"
case=STRING|"0"
extended=STRING|"0"
line00000000=STRING|"{line}"
linecount=STRING|"1"
multiline=STRING|"0"
noautocapture=STRING|"0"
pattern=STRING|"(?i)^(\d+|\d+_v\d+)\.jpg$"
savesubexpression=STRING|"0"
singleline=STRING|"0"
subexpressionpos=STRING|"0"
ungreedy=STRING|"0"
useexternal=STRING|"0"
variable=STRING|"valid"

[Actions\Action4]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action4\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{Valid}"

[Actions\Action5]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action5\Params]
message=STRING|"{line} is valid"
type=STRING|"3"

[Actions\Action6]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"

[Actions\Action7]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action7\Params]
message=STRING|"{line} is INVALID"
type=STRING|"2"

[Actions\Action8]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action9]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

Oleg Yershov
sarnusch
Posts: 35
Joined: Thu Apr 28, 2022 9:05 am

Re: Check if variable is numeric

Post by sarnusch »

Hi,
thanks for the quick response.
I have tested it and it works fine!

I am just getting this information after using the 'Test' button even if I use real data in the 'Specified Text' field:

Screenshot 2022-07-04 110509.png
Screenshot 2022-07-04 110509.png (109.63 KiB) Viewed 1665 times
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Check if variable is numeric

Post by Oleg »

the string {line} does not contain necessary expression
For testing put the name explicitly and press "Test"
At runtime RoboTask expands variable and put the name instead of {line}
Oleg Yershov
sarnusch
Posts: 35
Joined: Thu Apr 28, 2022 9:05 am

Re: Check if variable is numeric

Post by sarnusch »

Hello Oleg,
ok, It was my mistake because I misunderstood the error message.
It works now as expected.
Post Reply