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
  •  Hi  
    Have those global variables been initialized before they are used? They should be initialized with the default trend tag names in the startup Cicode function in your project.

    ~jacky

  • Hello Jacky and thanks for your reply.

    I have used Citect for quite a few years now but only ever hacked around in Cicode.

    I'm not sure quite what you mean by initialized.

    Our startup Cicode is quite simple, not much functionality.

    Do I have to initialize in this section?

    // DESC: This is the routine that gets called on startup of Citect.
    // FUNCTIONS: BB_Startup()
    // ServerActive()
    //
    //**************************** GLOBAL VARIABLES *****************************

    //**************************** GLOBAL CONSTANTS *****************************
    //**************************** MODULE VARIABLES *****************************
    MODULE INT mhSQL_TestConnection=-1; //SQL Handle of test connection to database
    //**************************** MODULE CONSTANTS *****************************

    Again thanks for your help.

    Kindest regards

    Daryl

  • It is the good practice to assign the default values to those Module or Global Cicode variables. You can assign the values in Declaration Statements. For example,

    //**************************** GLOBAL VARIABLES *****************************
    GLOBAL STRING TrendPen1 = "MyTrendTag1";
    GLOBAL STRING TrendPen2 = "MyTrendTag2";

    These default trend tags should be already defined in the system model in your project.

    I suppose that these global variables are assigned with new values dynamically at runtime depending on which trends you are interested in. 

    Also, in your original post, you stated

    BlockedTrnSetPen(86,1,( TrendPen1) )

    Should it read 

    BlockedTrnSetPen(86,1, TrendPen1 )

    No need to use brackets around a global variable  

Reply
  • It is the good practice to assign the default values to those Module or Global Cicode variables. You can assign the values in Declaration Statements. For example,

    //**************************** GLOBAL VARIABLES *****************************
    GLOBAL STRING TrendPen1 = "MyTrendTag1";
    GLOBAL STRING TrendPen2 = "MyTrendTag2";

    These default trend tags should be already defined in the system model in your project.

    I suppose that these global variables are assigned with new values dynamically at runtime depending on which trends you are interested in. 

    Also, in your original post, you stated

    BlockedTrnSetPen(86,1,( TrendPen1) )

    Should it read 

    BlockedTrnSetPen(86,1, TrendPen1 )

    No need to use brackets around a global variable  

Children
  • Hello again Jacky and thanks again for your reply.

    I will try defining default values.

    The global variables are being assigned with new values dynamically at runtime. I know this is working as I can see the correct value in the cicode global variable debug window. If I hard code the example trend tag I'm using into the super genie function call, everything works fine.

    The problem is when I try and pass the dynamically assigned global variable arguments into the function, I get a bad value in the debug stack window.

    As for brackets around variable, I have tried no brackets, quotes and myriad of other combinations from scouring cicode forums etc.

    Thanks again for your help.

    Regards

    Daryl