Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Regardign variable scope

Author
Message
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Sep 2003 01:00 Edited at: 9th Sep 2003 01:01
can someone tell me the difference between


global intMyVar as integer (application global?)
vs.
intMyVar as integer (is already module global?)


also, If I define a variable within a sub...
_MySub:
x as integer
do whatever
Return

what is the scope of variable x? Does it die when sub dies?

Just trying to sort variable scope in dbp
Thanks

-RUST-
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 9th Sep 2003 02:37
Ok, first there are two scopes within DBPro.

1. Outside functions (Outer scope)
2. Inside functions (Inner scope)

Note ... Functions, and not subroutines. Subroutines do not have a separate scope.

Now for the outer scope level:

a as integer : ` local
local b as integer : ` local
global c as integer : ` global
dim a(0) as integer : ` global
local dim a(0) as integer : ` global - the local keyword is ignored
global dim a(0) as integer : ` global

Inner scope:

a as integer : ` local unless declared global in outer scope
local b as integer : ` local
global c as integer : ` don't do this - it won't do what you expect and is meaningless anyway
dim a(0) as integer : ` local
local dim a(0) as integer : ` local
global dim b(0) as integer : ` don't do this unless you know what you are doing
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 9th Sep 2003 03:19
Thanks!

-RUST-

Login to post a reply

Server time is: 2026-07-25 08:12:06
Your offset time is: 2026-07-25 08:12:06