Variable Time Difference

Discuss RoboTask here
Post Reply
chrisk1
Posts: 6
Joined: Thu Nov 06, 2014 5:16 pm

Variable Time Difference

Post by chrisk1 »

I have a simple task for calculating the run time of a task.
Set a var with DateTime at the Start, set a different var with DateTime at the end.
Store the result from Time Difference in a Third var.

For some reason, the result is always 0. Any ideas?

*NOTE: This example doesn't have a pause, but I tested this with a 30 second pause"

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|0
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task6"
Hide=INTEGER|0
ID=INTEGER|1778460593
LogOnAsUser=INTEGER|1
Name=STRING|"Time Difference Task"
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

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""START_TASK"" with value ""{DateTime}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"START_TASK"
varvalue=STRING|"{DateTime}"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""[{Start_Task}]"" and play sound"
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"[{Start_Task}]"
msg2=STRING|"START"
msgcount=STRING|"3"
playsound=STRING|"1"
showmessage=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""END_TASK"" with value ""{DateTime}"""
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"0"
varkind=STRING|"1"
varname=STRING|"END_TASK"
varvalue=STRING|"{DateTime}"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""[{End_Task}]"" and play sound"
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"[{End_Task}]"
msg2=STRING|"END"
msgcount=STRING|"3"
playsound=STRING|"1"
showmessage=STRING|"1"

[Actions\Action5]
ActionID=STRING|"A_TIMEDIFFERENCE"
Enabled=INTEGER|-1
Name=STRING|"Time Difference"
Params=FOLDER

[Actions\Action5\Params]
datetime1=STRING|"{START_TASK}"
datetime2=STRING|"{END_TASK}"
format=STRING|"0"
valuekind=STRING|"0"
varname=STRING|"TASK_TIME"

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""[{Task_Time}]"" and play sound"
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"1"
msg0=STRING|"[{Task_Time}]"
msg2=STRING|"Time to Complete!"
msgcount=STRING|"3"
playsound=STRING|"1"
showmessage=STRING|"1"
Oleg
Site Admin
Posts: 3010
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Variable Time Difference

Post by Oleg »

Pay attention to this option, please
Image
If it is ON then the action calculates the value and save the result into variable
If it is OFF then the action saves specified string as-it-is. So you get the current date-time value in variable START_TASK, because RoboTask calculates the value every time when you use this variable.

Read more details here: https://robotask.com/forum/viewtopic.php?f=1&t=2359

Also see your corrected task below
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task22"
Hide=INTEGER|0
ID=INTEGER|1778460593
LogOnAsUser=INTEGER|1
Name=STRING|"Time Difference Task (corrected)"
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

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""START_TASK"" with value ""{DateTime}"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"1"
varkind=STRING|"1"
varname=STRING|"START_TASK"
varvalue=STRING|"{DateTime}"

[Actions\Action2]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""[{Start_Task}]"" and play sound"
Params=FOLDER

[Actions\Action2\Params]
icon=STRING|"1"
msg0=STRING|"[{Start_Task}]"
msg2=STRING|"START"
msgcount=STRING|"3"
playsound=STRING|"1"
showmessage=STRING|"1"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_CREATE"
Enabled=INTEGER|-1
Name=STRING|"Create local variable ""END_TASK"" with value ""{DateTime}"""
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"1"
varkind=STRING|"1"
varname=STRING|"END_TASK"
varvalue=STRING|"{DateTime}"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""[{End_Task}]"" and play sound"
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"[{End_Task}]"
msg2=STRING|"END"
msgcount=STRING|"3"
playsound=STRING|"1"
showmessage=STRING|"1"

[Actions\Action5]
ActionID=STRING|"A_TIMEDIFFERENCE"
Enabled=INTEGER|-1
Name=STRING|"Time Difference"
Params=FOLDER

[Actions\Action5\Params]
datetime1=STRING|"{START_TASK}"
datetime2=STRING|"{END_TASK}"
format=STRING|"0"
valuekind=STRING|"0"
varname=STRING|"TASK_TIME"

[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""[{Task_Time}]"" and play sound"
Params=FOLDER

[Actions\Action6\Params]
icon=STRING|"1"
msg0=STRING|"[{Task_Time}]"
msg2=STRING|"Time to Complete!"
msgcount=STRING|"3"
playsound=STRING|"1"
showmessage=STRING|"1"
Oleg Yershov
Post Reply