Hey, thanks for all the help on this basic question.  I'm trying to get
adjust from the perl way of doing things.

-Garman



===========

Message: 3
Date: Mon, 25 Feb 2002 23:09:39 -0500
To: [EMAIL PROTECTED]
From: Tab Julius <[EMAIL PROTECTED]>
Subject: Re: <lingo-l> Very basic variable question.
Cc: <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]


You have discovered what's known as a "local" variable.  The variable is
local to the handler (in this case, 'mouseUp') and doesn't persist past the
end of the handler.  It goes what is known as "out of scope" and no longer
exists.  The next time in, a new one is created, and initialized to VOID (a
null value).

If you declare the variable as 'global', it will persist outside of the
handler, meaning that it will always be "in scope" (as long as you specify
that you're using the 'global' version.  That will allow you to increment
it each time through.

You will also want to initialize it.

The minimum solution is:

  on mouseUp
    global gIncre

    gIncre =gIncre + 2
    put gIncre
  end

This will add 2 to the variable each time.  Saying it's in the global
namespace means that any references to gIncre in that scope (in this case,
the handler) will refer to the global version.

NULL translates to 0, and you can get away with it, but a better solution
(more correct) would be:

  on mouseUp
    global gIncre

    if (voidP(gIncre)) then
       gIncre =0
    end if

    gIncre =gIncre + 2
    put gIncre
  end


So, the first time through it will be void and you will initialize it to
0.  Effectively the same, but a bit more correct this way.

- Tab

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to