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 / Function problems returning value

Author
Message
PresFox
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 16th Sep 2005 13:52
Hello,

I am having trouble with returning a value entered with INPUt in a function:



When i now call the function and print the returned variable:



I allways get 0, whatever i enter

how can i solve this?

Microsoft isnt evil, they just make really crappy operating systems -- Linus torvalds
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 16th Sep 2005 14:10
There's nothing wrong with your function, but it's with the way you are trying to use the value returned from the function.

Whenever you use a variable inside a function, it cannot be accessed from anywhere else in the program except from within that function.

It seems a little weird at first, but once you get used to it, it's a very nice thing to take advantage of.

To answer your question, when a value is returned from a function, you need to 'capture' it into a variable of some sort, or output it straight away.

such as;


or;


There's also another issue with what you are actually trying to do.
When you get input from the user, it will always be in a string ( which you have ), however, what you are after is an integer number... So, you need a way to convert from a string to an Integer.
To do that, you want to use the Val() command.

Hope that helps

Jess.

Team EOD :: All-Round Nice Guy
Want Better dbHelp Files?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 16th Sep 2005 16:35
Quote: "When you get input from the user, it will always be in a string"


Input doesn't always use a string. You won't need VAL() if you use a numeric variable on the Input line:

Input "Enter A Number Between 1 And 100: ";NumVal

... or am I misunderstanding what you are saying?

TDK_Man

PresFox
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 16th Sep 2005 21:40
your not, already got that figured out

Microsoft isnt evil, they just make really crappy operating systems -- Linus torvalds
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 16th Sep 2005 22:07
From personal experience, stopping for input during a function has never worked for me...

My question is: Does this need to be a function? My guess is that standard code will work:



I don't know for sure this is what you're trying to achieve - but setting a connection, for me has never needed to be a function - and the code above, I think has the effect you're trying to achieve (it's the same, just not a function) -- Hope this has helped in someway...

...maybe one day I'll finish a project
PresFox
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location:
Posted: 17th Sep 2005 00:07
well im using this a couple of times in the program, putting it inside a function just makes less typing

it works anyways now

Microsoft isnt evil, they just make really crappy operating systems -- Linus torvalds

Login to post a reply

Server time is: 2024-11-27 18:35:11
Your offset time is: 2024-11-27 18:35:11