FUNCTION

HI
I’am trying to make calculation in my Flex 205 using script function. I have tags declare in the Ewon and using ONCHANGE “Deverse_06_St_Joseph”,"@Conv_06_ST_Joseph()"
but nothing appear to work. I need to return the value, Cumul_06_St_Joseph@ and Temp_06_St_Joseph@. Could you help me and Thank’s for the help

ONCHANGE “Deverse_06_St_Joseph”,"@Conv_06_ST_Joseph()"

FUNCTION Conv_06_ST_Joseph()
A% = Deverse_06_St_Joseph@

IF A% = 1 THEN
// Get Time value
A_Day$ = TIME$
A_Count% = A_Count% + A%
// Convert String Date To Interger
A_Conv% = FCNV A_Day$,40
ELSE
IF A% = 0 THEN
A_Day_Off$ = TIME$
A_Conv_2% = FCNV A_Day_Off$,40
A_TOTAL% = A_Conv_2% - A_Conv%
ENDIF
ENDIF
A_Cumul% = A_Cumul% + A_Total%
A_Float = A_Cumul%/60
Cumul_06_St_Joseph@ = A_Count%
Temp_06_St_Joseph@ = A_Float
ENDFN

Hello @Marc,

What exactly are you looking for help with? What errors are you seeing in the console when the function runs? This should point you towards any issues with the code. You can also use the Print statement to add debugging comments to the code.

Deryck

Couple of things. Check the quotes around the tag in the ONCHANGE, maybe it was just a copy error but they are different than the ones around the function call.

Is the tag Deverse_06_St_Joseph just an on and off tag? Does it just have either a 1 or 0 value?
The variables A_TOTAL% and A_Count% and A_Cumul% are not defined in this function are they declared someplace else?

Here are some changes.

FUNCTION Conv_06_ST_Joseph()
A% = Deverse_06_St_Joseph@
// if this is from another tag can set it here
A_TOTAL%=0
// if this is from another tag can set it here
A_Cumul%=0

IF A% = 1 THEN
// Get Time value
A_Day$ = TIME$
//A_Count% = A_Count% + A%
Cumul_06_St_Joseph@ = Cumul_06_St_Joseph@ + A%
// Convert String Date To Interger
A_Conv% = FCNV A_Day$,40
ELSE
IF A% = 0 THEN
A_Day_Off$ = TIME$
A_Conv_2% = FCNV A_Day_Off$,40
A_TOTAL% = A_Conv_2% - A_Conv%
ENDIF
ENDIF

A_Cumul% = A_Cumul% + A_Total%
A_Float = A_Cumul%/60
Cumul_06_St_Joseph@ = A_Count%
Temp_06_St_Joseph@ = A_Float

ENDFN

As Deryck said you can use print statements and also use break points in the Basic IDE window to step through the code and see where the problems are at.

1 Like

Hi

No They are local variable to the function and yes the tags Deverse_06_St_Joseph is declare as On Off in the Ewon Value

Hi

Here is the error that I get and I get and I cannot set Tags A_Cumul%=0 because it count the total of time that it was on. In fact I ‘am count the number of time the tags goes on and the accumulate time is was on for a day, I do reset this tags at midnight with ONTIME. Do I have to declare the local tags and if so how

Best regards

image001.jpg

You can declare the variables out side of the function but within the init section. This with only initialize them on startup. If you need them to retentive with a reboot you can setup a memory tag and make it retentive.

image