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 / Fine tuning my Input(), Process(), Output() functions

Author
Message
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 24th May 2010 04:28 Edited at: 24th May 2010 09:04
Hey everyone,

I'm just practising writing functions, but I'm still stumbling at passing values to and from them. If I can, I'd like to avoid declaring variables as global just to get them working with functions. Have a look at my code below;



If you can assist me in tidying up this example, I'd be most great full.

Here's another example, it only works if I declare y$ as global.



At the "Endfunction" line, I think I've seen examples where programmers put a return value, like "Endfunction y$" but I don't quite understand this either...


Cheers in advance,
BFM

EDIT: Tidied up my example a bit.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 24th May 2010 10:34
Alright I'll take a try:

And of course I'll try to leave the actual coding to you.

You can return Test as a value of your function:


You can then use that Test as a parameter:


You can also make your code shorter by using the command lower$(), which converts your string to lowercase.
So instead of testing for "red", "Red" and "RED", you can do this:
Test$ = lower$(Test$)
and then only check for "red" since you know there are only lowercase characters in the string.

Cheers!
Sven B

Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 24th May 2010 15:14
Thanks Sven B, I can't thank you enough for helping me with understanding this. I've come across so many threads about functions that do nothing but confuse me!

I've got my code sorted, posted as per below. A few small bugs to iron out, but the penny has finally dropped with functions.



All along, instead of calling functions or trying to pull a value from then directly, such as;



All I had to do was declare a variable with that function, then use that variable, such as;



NOW, I'd appreciate if anyone else can hit me up on my bad habits, as it's best I learn how to code correctly from the start!
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 24th May 2010 18:53
I had no idea you could seperate values with commas in a case statement :/

Learn someth new every day...



Login to post a reply

Server time is: 2024-09-28 18:23:12
Your offset time is: 2024-09-28 18:23:12