Announcement

Collapse
No announcement yet.

Why local variables have some value after enter the function?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why local variables have some value after enter the function?

    I have coded to switch the page like this. Gen4-ulcd-70dct, visi.

    func form1()

    var state,Wbs1,n,x,y,i,j;
    var _returnValue;
    var posn1;
    var receivetemp[20];
    var ps,k,ch;
    var ptrbuff1,ptrbuff1min;
    var ptr,ptr2,char,idx;
    var read00[3];
    var read01[2];
    var read02[2];
    var read03[12];
    var read04[2];
    var read05[2];
    var readtar[6]:=[read00,read01,read02,read03,read04,read05];
    var buffer[30],p,q;
    var tarnum,num,cha;
    gfx_Cls();
    changepage1();
    txt_FGcolour(RED) ;
    txt_MoveCursor(0,0);
    touch_Set(TOUCH_ENABLE);

    ptrbuff1 := str_Ptr(receivetemp);
    ptrbuff1min := ptrbuff1;
    print([STR]readtar[0],"\n");
    print([STR]readtar[1],"\n");

    repeat

    ch := serin1();
    if(ch > 0)

    .........
    .........and so on.

    I first start the application shows page1[func form1()].
    There is nothing in readtar[0],[1]...
    after I change to other page and come back to page1.
    I get something left in readtar[0],[1]...

    pls. help
    Best regards,
    pakorn

  • #2
    Hello,

    After looking at your codes, even though incomplete, my assumption is that you're
    getting those values from the last instance you've assigned a value to them.

    My suggestion is, to reset them back to zero once you exit a function, in your
    code it's form1(). You may try to add this code at the end of the function, outside
    the repeat forever loop:
    Code:
    var i;
    for (i := 0; i < 5; i++)
       readtar[i] := 0;
    next
    If this doesn't work for you, you may upload your code here so we could investigate
    further and suggest a better solution.

    Good luck and best regards,
    Sherwin

    Comment


    • #3
      Hello Sherwin,

      Yes I get the last instance.
      Can I just send you the project code via email.
      It is 22912 bytes now.

      Best regards,

      Comment


      • #4
        Hi,

        Please do send your code.

        Here is my email address: sherwin.macabio(at)4dsystems.com.au
        Replace with "@".

        Best regards,
        Sherwin

        Comment

        Working...
        X