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 / Functions forget variables?

Author
Message
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 18th Feb 2005 05:17
In my code i use functions. But when i use a function, it forgets the varibles which i set previously. Is there a way around this?

Thanks in advance
Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 18th Feb 2005 05:27
yes. define your variables at the top of your code as globals. I t will look a bit like this:



Part of solving the problem is actually noticing that the problem is there in the first place

Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 18th Feb 2005 06:21
But i set the varible half way through the code :S The user holds down the enter key for how much power he wants
Clueless
20
Years of Service
User Offline
Joined: 16th Feb 2004
Location: Corbin, KY, USA
Posted: 18th Feb 2005 10:53
Quote: "But i set the varible half way through the code :S The user holds down the enter key for how much power he wants "


If you mean you've declared it global and it still doesn't seem to be recognized in your function, check the spelling of the variable name. A typo means you're looking at the wrong variable.
Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 18th Feb 2005 23:18
just create the variable at the top of the code like this:



It doesn't matter what you do with it in your program, just set it as global at the top and the function will be able to access it.

Part of solving the problem is actually noticing that the problem is there in the first place

Monsieur Mort
19
Years of Service
User Offline
Joined: 12th Feb 2005
Location:
Posted: 19th Feb 2005 22:53
I'd been wondering what globals were - saw them in a snippet but couldn't find them in the help files. Stupid help files...

So a global variable is just one that can be accessed (read and altered) by functions?

Why do you sink I ave zees outRAGEOUS accente?!
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 21st Feb 2005 04:32
Okay i understand now

Thanks!

Login to post a reply

Server time is: 2024-11-11 23:50:25
Your offset time is: 2024-11-11 23:50:25