Page 1 of 1
how check if variable exists
Posted: Sat Oct 13, 2018 10:51 pm
by theimer
hello,
exist any way how to how check if variable exists? I tried "If is empty", but it does not operate.
Libor
Re: how check if variable exists
Posted: Tue Oct 16, 2018 10:47 am
by Rukbunker
Post your task. Makes it easier to exactly answer your question.
Re: how check if variable exists
Posted: Tue Oct 16, 2018 11:35 am
by Oleg
You can use this script top check
Code: Select all
function CheckVar(VarName)
expr = "{"+VarName+"}"
s = RoboTaskApp.ExpandText(expr)
if s = expr then
CheckVar = "False"
else
CheckVar = "True"
end if
end Function
'LogMessage(CheckVar("date"))
If variable exists then
ExpandText method returns the value of variable. Otherwise it keeps the expression unchanged
Also look at the example below
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1604865554
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task414"
Hide=INTEGER|0
ID=INTEGER|-1593153984
LogOnAsUser=INTEGER|1
Name=STRING|"Check existence of variables"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
[Actions\Action1]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER
[Actions\Action1\Params]
destvar=STRING|"VARNAME"
line0=STRING|"Date"
line1=STRING|"MyVarName"
line2=STRING|"DateTime"
linecount=STRING|"3"
sourcetext=STRING|"1"
[Actions\Action2]
ActionID=STRING|"A_SCRIPT_VBEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"VB Evaluate (check existence)"
Params=FOLDER
[Actions\Action2\Params]
expression=STRING|"CheckVar(""{VarName}"")"
line00000000=STRING|"function CheckVar(VarName)"
line00000001=STRING|" expr = ""{""+VarName+""}"""
line00000002=STRING|" s = RoboTaskApp.ExpandText(expr)"
line00000003=STRING|" if s = expr then"
line00000004=STRING|" CheckVar = ""False"""
line00000005=STRING|" else"
line00000006=STRING|" CheckVar = ""True"""
line00000007=STRING|" end if"
line00000008=STRING|"end Function"
line0000000A=STRING|"'LogMessage(CheckVar(""date""))"
linecount=STRING|"11"
loadfromfile=STRING|"1"
variable=STRING|"res"
[Actions\Action3]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action3\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"0"
type=STRING|"3"
value1=STRING|"{res}"
[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Variable {VarName} exists"""
Params=FOLDER
[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"Variable {VarName} exists"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action5]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"
[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Variable {VarName} doesn't exist!!!"""
Params=FOLDER
[Actions\Action6\Params]
icon=STRING|"3"
msg0=STRING|"Variable {VarName} doesn't exist!!!"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action7]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action8]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Do not forget to enable the task after importing.
Maybe it's necessary to add such action. I wrote this into our ToDo.
Re: how check if variable exists
Posted: Wed Oct 17, 2018 3:17 pm
by theimer
thank you very much