Read in and use local variables at runtime

Discuss RoboTask here
Post Reply
DK.Ideagen
Posts: 22
Joined: Wed Mar 09, 2022 10:33 pm

Read in and use local variables at runtime

Post by DK.Ideagen »

I have a text file variables.txt

it contains for as a sample

Code: Select all

var1 = Min. horizontal separation
var2 = Min. horizontal separation unit
var3 = Angle
how can I use that file to add local variables at runtime so for example I could use {var3} in the script.

Code: Select all

I do not wish to copy and paste the text into the task editor 
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Read in and use local variables at runtime

Post by Oleg »

look at my example

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1163085779
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task38"
Hide=INTEGER|0
ID=INTEGER|-1684481408
LogOnAsUser=INTEGER|1
Name=STRING|"Load variable at runtime"
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
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_MISC_COMMENT"
Enabled=INTEGER|-1
Name=STRING|"//I use variable in the task, but you can read it from file "
Params=FOLDER

[Actions\Action1\Params]
comment=STRING|"I use variable in the task, but you can read it from file "

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|0
Name=STRING|"Set variable ""txt"" with value ""{TextFile(c:\temp\RuntimeVars.txt)}"" //you can read it from file"
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"1"
varname=STRING|"txt"
varvalue=STRING|"{TextFile(c:\temp\RuntimeVars.txt)}"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""txt"" with your text"
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"0"
varname=STRING|"txt"
varvalue=STRING|"var1 = Min. horizontal separation{EOL}var2 = Min. horizontal separation unit{EOL}var3 = Angle"

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

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

[Actions\Action5]
ActionID=STRING|"A_VARIABLES_DELIMITED"
Enabled=INTEGER|-1
Name=STRING|"Split Text"
Params=FOLDER

[Actions\Action5\Params]
colon=STRING|"0"
comma=STRING|"0"
other=STRING|"1"
otherchar=STRING|"="
quote=STRING|"2"
semocolon=STRING|"0"
space=STRING|"0"
spaceasone=STRING|"0"
string=STRING|"{Line}"
tab=STRING|"0"
variable=STRING|"Line"

[Actions\Action6]
ActionID=STRING|"A_STR_TRIM"
Enabled=INTEGER|-1
Name=STRING|"STR Trim"
Params=FOLDER

[Actions\Action6\Params]
custom=STRING|"0"
eol=STRING|"1"
lead=STRING|"1"
source=STRING|"{Line(0)}"
spaces=STRING|"1"
tabs=STRING|"1"
trailing=STRING|"1"
variable=STRING|"VarName"

[Actions\Action7]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""{VarName}"" with value ""{Line(1)}"""
Params=FOLDER

[Actions\Action7\Params]
expand=STRING|"1"
varname=STRING|"{VarName}"
varvalue=STRING|"{Line(1)}"

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

[Actions\Action9]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{var1}"""
Params=FOLDER

[Actions\Action9\Params]
icon=STRING|"1"
msg0=STRING|"{var1}"
msg1=STRING|"{var2}"
msg2=STRING|"{Var3}"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"

Oleg Yershov
DK.Ideagen
Posts: 22
Joined: Wed Mar 09, 2022 10:33 pm

Re: Read in and use local variables at runtime

Post by DK.Ideagen »

Perfect, thank you
Post Reply