Variable Scope in a Table

bhalpinbhalpin Member Posts: 309
Hi. This has me baffled.

I have a form with SourceTable T

The form calls T's function (call it T.F1) to pass values to the table.
The call looks like F1(value1,value2,value3, etc.)

T.F1 sets globals in the table to the passed values and returns.

The form calls another function (call it 'T.F2') in the table.

In T.F2, the globals set before are all there.

T.F2 then calls another function in the same table (T.F3)

In T.F3 all the globals are empty/zero.


I know there has to be a good explanation for this ... :-k

Can anyone shed some light on this?

Thanks!

Comments

  • kapamaroukapamarou Member Posts: 1,152
    Maybe this helps...

    viewtopic.php?f=23&t=41868
  • DenSterDenSter Member Posts: 8,305
    It's probably because F3 is looking at a different variable. I've seen many times that local and global variables have the same names, and scope gets confused sometimes.
  • bhalpinbhalpin Member Posts: 309
    Hi. Thanks all.

    By the way Denster - there is no collision between local and global variables.

    I tried modifying the code as follows:

    Form calls Table function T.F1 with several parameters.

    T.F1 sets globals in the table to the passed values.

    T.F1 then calls function T.F2 to verify the variables all have values.

    In T.F2 the global values all have the expected values.

    T.F1 then calls T.F3 to do some work using the global variables.

    In T.F3 the variables are all empty.

    The behaviour is weird - especially since this is all happening in one function call to the table that spawns other function calls (presumably) withing the same table/record.

    But, this is NAV, so things can get "interesting" ... and in this case it looks like the scope/persistence of globals in a record is somewhat "undefined".

    Thanks all, I've already worked around it (by holding my nose and pulling the code into the form.)

    B
  • BeliasBelias Member Posts: 2,998
    this one can help, too!it happened to me...
    http://www.mibuso.com/forum/viewtopic.php?f=23&t=42760
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • vijay_gvijay_g Member Posts: 884
    DenSter wrote:
    It's probably because F3 is looking at a different variable. I've seen many times that local and global variables have the same names, and scope gets confused sometimes.

    not confusion,it's looking as when a local variable has same name to global variable then the local variable overright to global in his scope(you can not use global variable in local scope it hide to global).
Sign In or Register to comment.