Pass a cicode global variable argument into a function that is called by a super genie graphic window

 I am having trouble passing a global cicode variable to the BlockedTrnSetPen function, which is called by the trend pop up page (super genie).

//**************************** GLOBAL VARIABLES *****************************
GLOBAL STRING TrendPen1;
GLOBAL STRING TrendPen2;
GLOBAL STRING TrendPen3;
GLOBAL STRING TrendPen4;

Super genie cicode function call by event on 'On page shown'

BlockedTrnSetPen(86,1,( TrendPen1) )

INT
FUNCTION
BlockedTrnSetPen(INT hAN, INT nPen, STRING sTrend)
INT timeout = 5000
INT sleepTime = 10
INT error = -1
INT elapsed = 0
INT currentTime
STRING sPenName
error = TrnSetPen(hAN, nPen, sTrend)
IF error = 0 THEN
error = -1
currentTime = SysTime()
WHILE error <> 0 AND elapsed < timeout DO
sPenName = TrnGetPen(hAN, nPen)
IF sPenName = sTrend THEN
error = 0
ELSE
SleepMS(sleepTime)
elapsed = elapsed + SysTimeDelta(currentTime)
END
END
END
RETURN error
END

In debug first two arguments are passed ok but global variable argument debug shows bad  and value of 0.00 for global variable string argument.

Any thoughts?

Thanks

Daryl

Parents
  • If I understand correctly, you try to use a global CICODE variable in a function call on a graphics page.
    That will not work. Cicode variables are only valid in cicode, not on pages, in events, or anywhere else in the system.

    To achieve what you want, you have to use Local Variables. These are tags, declared in the Studio (or Project Editor for older versions), NOT in cicode.

    To understand the difference between the different kinds of tags and variables, you could take a look at KB article 000025797, but unfortunately the scope is not explained very well. I'll list a full reference here:

    Variable type Declared in Scope in Cicode functions Scope in Citect processes Machine scope
    Local cicode variable Cicode (function) Local (within single function) Local (cicode only) Local
    Module cicode variable Cicode (file header) Module (across functions within same cicode file) Local (cicode only) Local
    Global cicode variable Cicode (file header) Global (across all cicode functions) Local (cicode only) Local
    Local Variable Studio Global (across all cicode functions) Local (all purposes) Local
    Variable Tag Studio Global (across all cicode functions) Global (across all processes) Global (across all nodes in network)

    Hope this helps,

    Best regards,

    Patrick

  • Hello Patrick,

    Firstly, thank you very much for your help.

    Yes you did understand correctly.

    The documentation wasn’t crystal clear, saying a cicode global variable couldn’t be used on a graphic page, but I wasn’t sure if that included being passed as an argument to a cicode function that was called from a graphic page.

    Your solution of using a local variable worked perfectly.

    I can’t thank you enough as the problem this function is fixing has plagued the plant for many years.

    Many attempts to fix have been done before but none successful. Hopefully you have been part of a solution to a very long-standing problem.

     

    Kindest regards

     

    Daryl

  • You're welcome, glad I could help.

    I agree that documentation could be improved on this point.

  •   nice suggestion to improve the article! Thanks!

Reply Children
No Data