Ondate

Hi, I’m trying to turn on a variable (ComputeEnable)at a given time with an ONDATE and turn it off at an other time with another ONDATE.
The thing is the program seems gets stuck in mylabel2

I was thinking when ondate triggers , it would execute mylabel2 once and not go back until ondate triggers again

thanks for your help

The script looks like this

ONDATE 2,“05 10 * * *”,“GOTO mylabel2”
mylabel2:
ComputeEnable@ = 1
StartDayTime@ = Getsys Prg, “TimeSec”
TotalizedTime@ = 0
OnPerCent@ = 0
Print 2
End
ONDATE 3,“10 10 * * *”,“GOTO mylabel3”
mylabel3:
ComputeEnable@ = 0
EndDayTime@ = Getsys Prg, “TimeSec”
TotalizedTime@ = 0
OnPerCent@ = 0
Print 3
End
ActualOnGoingTime@ = Getsys Prg, “TimeSec”
ActualDayTime@ = ActualOnGoingTime@ - StartDayTime@

IF ComputeEnable@ THEN
If DI1@ And mystep@ = 13 Then
Ontime@ = Getsys Prg, “TimeSec”
mystep@ =11

Hello @PhilippeHamel,

Is this your whole coding section?

In this line:

“IF ComputeEnable@ THEN”

You’re making an if statement that has no comparison, it may be running into faults from this. You could also rewrite them to be functions instead.

ONDATE 2,“05 10 * * *”,“@mylabel2()”
ONDATE 3,“10 10 * * *”,“@mylabel3()”

Function mylabel2()
ComputeEnable@ = 1
StartDayTime@ = Getsys Prg, “TimeSec”
TotalizedTime@ = 0
OnPerCent@ = 0
Print 2
Endfn

Function mylabel3()
ComputeEnable@ = 0
EndDayTime@ = Getsys Prg, “TimeSec”
TotalizedTime@ = 0
OnPerCent@ = 0
Print 3
Endfn

Thank you Tim, I do have more code than what i posted I just didnt want to put too much on the post ,

i ll try what you suggest

“IF ComputeEnable@ = 1 THEN”
and function instead

thanks

Thanks let me know if you’re still running into issues after that

Hi Tim, I must not be using the ondate properly
i wanted to turn ComputeEnable on at 13:04 montreal time wich is the time written at bottom of device server page and turn it back off at 13:06. I could not see it change value

here is the whole code

thanks for your help

ONDATE 2,“4 13 * * *”,“GOTO myFunc2()”
Function myFunc2()
ComputeEnable@ = 1
StartDayTime@ = Getsys Prg, “TimeSec”
TotalizedTime@ = 0
OnPerCent@ = 0
Print 2
Endfn
ONDATE 3,“6 13 * * *”,“GOTO myFunc3()”
Function myFunc3()
ComputeEnable@ = 0
EndDayTime@ = Getsys Prg, “TimeSec”
Print 3
Endfn
ActualOnGoingTime@ = Getsys Prg, “TimeSec”
ActualDayTime@ = ActualOnGoingTime@ - StartDayTime@

IF ComputeEnable@ = 1 THEN
If DI1@ = 1 And mystep@ = 13 Then
Ontime@ = Getsys Prg, “TimeSec”
mystep@ =11
Endif
If DI1@ = 0 And mystep@ = 11 Then
Offtime@ = Getsys Prg, “TimeSec”
mystep@ =12
Endif
IF mystep@ =12 THEN
TotalTime@ = OffTime@ - Ontime@
TotalizedTime@ = TotalizedTime@ + TotalTime@
OnPerCent@ = (TotalizedTime@ / ActualDayTime@) * 100
mystep@ = 13
ENDIF
ENDIF
Print mystep@

This might help I just saw that

If you create a function, you don’t use goto.

It would be written like this:

ONDATE 2,“4 13 * * *”,“@myFunc2()”

I think it might just be a syntax error

thanks it works now!

Great! Glad to hear it’s up and running