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.

Newcomers DBPro Corner / Common Questions and answers

Author
Message
Mnemonix
23
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 19th Jun 2003 04:04
I have noticed some of the questions that are posted here on frequent occasions. I will answer those that i have the answer too.


1. How do local and global variables work

When a function is used in dbpro or db classic that function ignores all variables outside of itself unless they are global. Global variables are data that can be used at any point by any part of your program even if it is in functions that reside in different source files. A local variable wil only be valid inside the function tha declared it.

All variables declared at the top of your main source code are global as well as arrays and all other variables declared like this

GLOBAL var = value

If you use Labels and gosubs, these do not have their own set of variables and can therefore all local variables that existed in the procedure where gosub was located are valid in this subroutine. Not to mention all global variables anyway.
"We are getting aggravated"
"Yes, we are"
Bloodshot
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location: United Kingdom
Posted: 20th Jun 2003 16:25 Edited at: 20th Jun 2003 16:57
Mnemonix said:
Quote: "All variables declared at the top of your main source code are global as well as arrays and all other variables declared like this

GLOBAL var = value"


In DBPro, variables declared at the top of your program are NOT global just because you place them at the top of your program. You MUST declare them with the Global command to share the values held within them correctly inside and outside of Functions!
(Important: Make sure you declare the variables you want as Global before assigning values to them, else the values will be be lost when they are initialised with the Global Command - [This is why it's best to do it at the top of your program, first.])

Example:
John H
Retired Moderator
23
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 20th Jun 2003 16:30
Hey if this post keeps up it will be a good one to stick. Ill keep an eye on it when I can, and for the next five days, Im sure some other mod will.

Good work guys,

RPGamer

Current Project: Eternal Destiny
Questions? Comments? Suggestions? Go to the Eternal Destiny Forum!
Mnemonix
23
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 21st Jun 2003 01:17
I have read posts by Adminds and programmers notifying that vars defined at the top of the program are global. Can someone verify this please

"We are getting aggravated"
"Yes, we are"
Bloodshot
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location: United Kingdom
Posted: 21st Jun 2003 01:26 Edited at: 21st Jun 2003 01:28
Just test the example code I provided to confirm it for yourself. I'm giving advice from my own personal experience, not what I've read elsewhere.
Mnemonix
23
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 21st Jun 2003 01:30
Sorry, i havent tested your code yet. bear with me. Im having a few comp probs at the moment

"We are getting aggravated"
"Yes, we are"

Login to post a reply

Server time is: 2026-07-06 01:18:57
Your offset time is: 2026-07-06 01:18:57