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? constants?

Author
Message
EcEnSaNe
19
Years of Service
User Offline
Joined: 16th Dec 2004
Location:
Posted: 29th Dec 2004 02:36
i need some help with functions
alrihgt how do you pass values from a function back to the code it was called from...here is what i did




So it should print
Hello
123
123

but it prints
Hello
123
0

HELP???

oh yea and is tehre a way to do constants in this languge?
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 29th Dec 2004 03:27 Edited at: 29th Dec 2004 03:30
Variables in functions are local.
So a variable you use in a function is for that function only, outside of the function that value will be null. To make a function affect the other code, you either need to declare you variable as global or use the function to return the value.

This shows both ways:


You can also use constants:


or even:


Hope that helps abit.

#Edit, this all works in DBP, and should probably be the same in DBC too. But i haven't checked.


Cubes with guns? Something isn't right...
EcEnSaNe
19
Years of Service
User Offline
Joined: 16th Dec 2004
Location:
Posted: 29th Dec 2004 03:42
alright thanks..

i understand the constants that really helps thnx ^^

but im still lost on the functions...i get the whole global thing....and all that but why dosent my code work? becuase i wrote "EndFunction Asdf" so i think it should have passed back the value Asdf to the variable Asdf......becuase yours works like that....help?
ReD_eYe
21
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 29th Dec 2004 03:45


One slight change, the function returns a value, but it doesn't assign it to a variable, so assign the function to the variable:
Asdf = DoStuff()
Then print the variable:
Print Asdf
And it all works as you'd expect.


Cubes with guns? Something isn't right...
EcEnSaNe
19
Years of Service
User Offline
Joined: 16th Dec 2004
Location:
Posted: 29th Dec 2004 03:56
OHHHHHHHHHHHHHHHHHHHHHHHHHHHH

ok i get it now....i was thinking...yea ><

thnx ^^
nice sig btw
Carolina South
20
Years of Service
User Offline
Joined: 28th Sep 2004
Location: South Carolina
Posted: 30th Dec 2004 11:12
Thanks Red Eye. I found it useful also

"Diplomacy is the art of saying 'Nice doggie' until you can find a rock." - Will Rogers

"The secret to creativity is knowing how to hide your sources." - Albert Einstein

Login to post a reply

Server time is: 2024-11-11 22:37:31
Your offset time is: 2024-11-11 22:37:31