Normal Topic "var" declaration in GLOBAL CODE (Read 708 times)
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
"var" declaration in GLOBAL CODE
Apr 26th, 2006 at 9:06pm
Print Post Print Post  
In Sesame 1.1.3, you can (but never should) declare a variable in the Global Code section, globally (outside of any function or subroutine) using the "var" keyword. As in:

var MyVar as int

This has led to problems, both in the way the code then functions, and in how Sesame uses memory.

In 1.1.4 and in Sesame 2.0, this will not be a legal syntax. Variables declared in the Global Code area that are not inside a function or subroutine, will have to be declared using the "stat" keyword instead:

stat MyVar as int

So if you have variables declared in the Global Code area that are not declared inside of a function or subroutine, that are declared using the "var" keyword instead of the "stat" keyword, you should change them to use the "stat" keyword.

We are sorry for the inconvenience.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: "var" declaration in GLOBAL CODE
Reply #1 - Apr 26th, 2006 at 9:38pm
Print Post Print Post  
I will have to change quite a bit. What is the logic behind this? I thought when variable is declared in GlobalCode it is available to the all elements of the form of the record. Stat retains value in the result set across multiple records in the result set.  Is this right?

Bharat
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: "var" declaration in GLOBAL CODE
Reply #2 - Apr 26th, 2006 at 10:12pm
Print Post Print Post  
Quote:
I will have to change quite a bit. What is the logic behind this? I thought when variable is declared in GlobalCode it is available to the all elements of the form of the record. Stat retains value in the result set across multiple records in the result set.  Is this right?

Bharat


When a variable is declared in GLOBAL CODE as either var or stat, it is available to all events. Stat retains it's value after GLOBAL CODE has finished running. Var is only in scope while GLOBAL CODE is actually running. Therefore, variables declared as var in GLOBAL CODE have only very limited use. If you use them after GLOBAL CODE finishes running, the results can be unpredicatable.

If you are declaring variables in GLOBAL CODE in the first place, it is unlikely that you want a var. You probably wanted a stat all along.

You shouldn't have to change anything except the declaration itself. The rest of your code should be fine. You do want to make sure to initialize your stat variables as part of GLOBAL CODE to make sure they get a known starting value when you open your Form. For example:

Code
Select All
stat vMyVar as Int

	  vMyVar = 0 

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged