Normal Topic Subroutine and Static Variable (Read 618 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Subroutine and Static Variable
Oct 24th, 2006 at 8:11pm
Print Post Print Post  
Is it possible to have a Subroutine refer to a static variable?  I ask because I learned the other day that the Static Variable has to be defined after the Subroutine is, so it seems like the cart would be before the horse.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Subroutine and Static Variable
Reply #1 - Oct 24th, 2006 at 8:16pm
Print Post Print Post  
The static variable can be defined before the subroutine. It cannot be set to a value until after all your definitions (including subroutines and functions).

GLOBAL CODE:
Code
Select All
// Define Static Variable
stat sTemp as Int

// Define Subroutine which uses the static variable
SUBROUTINE DoIt()

	  WriteLn(sTemp)

END SUBROUTINE

// Set static variable to a value
sTemp = 50
 



  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Subroutine and Static Variable
Reply #2 - Oct 24th, 2006 at 8:18pm
Print Post Print Post  
Perfect, thanks Erika.
  

**
Captain Infinity
Back to top
IP Logged