Announcement

Collapse
No announcement yet.

Local GLOBAL declarations

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

  • Local GLOBAL declarations

    I have two functions that need a LOCAL variable (Index)
    that keeps the value it had from the last call.

    So I used:

    DIM Index AS GLOBAL LONG

    This works fine.

    Then I noticed that i accidentally deleted the declaaration from ONE
    of the functions and yet the program still compiled!

    As the variable name is the same in the other functions I assumed
    that somehow the declaration in one function is covering the other
    function

    Is this a bug?

    If not is the value of this variable going to be the same
    in each very different function?

    If it is the same what happens when I declare Index in each function
    as a GLOBAL variable?


    ------------------
    Kind Regards
    Mike

  • #2
    Mike,

    A GLOBAL is available throughout the scope of the program.
    To make a local variable retain its value between calls use

    STATIC Index as Long

    this goes inside the sub/function and is local to that
    sub/function only.

    Mike

    ------------------

    Comment


    • #3
      So whats a GLOBAL inside a function then?

      When would you use that?

      ------------------
      Kind Regards
      Mike

      Comment


      • #4
        I will leave Lance or someone else to answer that question. The only time
        I use GLOBAL inside a function or sub is when I DIM/REDIM an array that
        I have declared GLOBAL. I do this to insure that I am working
        with the correct array and not one I happened to have named the same
        inside a sub/function for local use. I wouldn't normally name a
        local array (or variable) the same is a GLOBAL one but I have been
        known to mess up on occasion.

        Lance/Tom and others may know of a reason to use GLOBAL inside
        a sub/function that I am unaware of.

        Mike

        ------------------

        Comment


        • #5
          Using DIM X AS GLOBAL LONG inside a sub or function is exactly the same as using GLOBAL X AS LONG outside a sub or function.

          If you want a local variable, use LOCAL not GLOBAL.

          -- Eric


          ------------------
          Perfect Sync Development Tools
          Perfect Sync Web Site
          Contact Us: mailto:[email protected][email protected]</A>

          [This message has been edited by Eric Pearson (edited September 14, 2001).]
          "Not my circus, not my monkeys."

          Comment


          • #6
            OK got it. Thx guys

            ------------------
            Kind Regards
            Mike

            Comment

            Working...
            X
            😀
            🥰
            🤢
            😎
            😡
            👍
            👎