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 / Retrieving variables from a function, DBP

Author
Message
GoPostal
20
Years of Service
User Offline
Joined: 9th Sep 2004
Location:
Posted: 16th Oct 2004 03:02
I have found that if I give a variable or string a value within a function, it does not have any value (variable is 0, string is empty (ie blank))

I tried converting the function to a sub-routine, and it worked (ie variables were the same outside subroutine)

So, my question is, how do I create a function where the variables exist outside, or am I stuck with sub-routines?
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 16th Oct 2004 03:09
If you define the variable as GLOBAL at top of your code, the variable can be used inside and outside of functions: e.g.



Boo!
GoPostal
20
Years of Service
User Offline
Joined: 9th Sep 2004
Location:
Posted: 16th Oct 2004 03:12 Edited at: 16th Oct 2004 03:41
Thanks. How do I do global for an array? Also, does it have to be at the beginning?
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 17th Oct 2004 06:59
I think I remember reading somewhere that dim makes the array global automatically, so long as the array is made from outside the function. I could however be utterly wrong.


IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Oct 2004 21:55
Dims that are executed outside of a function are automatically global, but I label mine as global anyway.



*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
The Wendigo
22
Years of Service
User Offline
Joined: 13th Sep 2002
Location: A hole near the base of a tree in the US
Posted: 18th Oct 2004 17:15
the fact that variables are erased out side of functions is because of encapsilation. Basically, it is a feature, not a bug. Looks like everyone else showed the workarounds so good luck!


Home of DOOP, Strata Works, and Height

Login to post a reply

Server time is: 2024-11-27 12:33:05
Your offset time is: 2024-11-27 12:33:05