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 not working help please?

Author
Message
yr un olaf
18
Years of Service
User Offline
Joined: 28th May 2006
Location:
Posted: 28th May 2006 19:14
ok i seem to be having a problem with this piece of code
do
print "input number"
input nbr
test(nbr)
print nbr
loop

function test(nbr)

if nbr = 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or 10 or 11 or 12 then
nbr = 1


if nbr <> 1
if nbr = 13 or 14 or 15 or 16 or 17 or 18 or 19 or 20 or 21 or 22 or 23 or 24 then
nbr = 2

else
nbr = 3
endif

endfunction nbr


obviously here i am trying to see, for example, if i input the number 12 then nbr becomes 1, or if i input 16 nbr becomes 2 and anything above 24 nbr becomes 3, but whatever i input and it then goes through the functio it just comes out as the same number. What can i do to fix this please?
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 28th May 2006 19:36
Try:

yr un olaf
18
Years of Service
User Offline
Joined: 28th May 2006
Location:
Posted: 28th May 2006 19:42
thank you very much thats great. i see what you did there
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 28th May 2006 20:12
D&D's (hee hee) function may work, but you might want to look into another way of thinking about your test:


Something you want to watch for is the 'scope' of your variables. You're using the nbr variable both inside and outside of a function, and you've not declared it as global. Now, I'm not sure if you have to in this situation, but if you're going to use variables both inside and outside (i.e. in your basic loop) a function, then it's best to declare them as global like this:

Otherwise, your program may quite happily forget about what you did to the variable while you are in the function. You only need to put that line in once, at the top of your code. My version should work too - but as you can see, I didn't use the same name in the variable.

Good luck.
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 28th May 2006 21:38
Hey Tinkergirl - I think you are the first to spot the acronym (although do you know where the full name comes from?)

I chose not to declare nbr as global and kept the ultra long 'or' statements to try and match as much as possible what 'Arrays and stuff' had started with.

Your code is a lot cleaner!
yr un olaf
18
Years of Service
User Offline
Joined: 28th May 2006
Location:
Posted: 29th May 2006 01:53
Thank you again to you both, thats exacly what i wanted to do
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 29th May 2006 17:26
Sandman?
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 29th May 2006 20:36
Another interesting command you might want to consider is SELECT and it's subcommand CASE. Useful if numbers are not in nice ranges.



Boo!
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 2nd Jun 2006 21:06
She gets it in one! Hats off to tinkergirl!

[I'm a big Gaiman fan - his books are fantastic and he is a really nice guy in person!]

Login to post a reply

Server time is: 2024-09-24 23:20:13
Your offset time is: 2024-09-24 23:20:13