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 return value

Author
Message
alanuk
21
Years of Service
User Offline
Joined: 25th Mar 2003
Location: United Kingdom
Posted: 18th Apr 2003 13:57
The following code I expected to return a value in 's' of 111 instead of zero. Any ideas please?

regards Alan
##################################################
` this should return a value of 111 (not 0)

` call function test
test(10)
print "return value " ; s
end


function test(count)
for t=1 to count
print t;","
next t
s=111
endfunction s
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 18th Apr 2003 16:16
instead of test(10) use:

s=test(10)

or replace this:

test(10)
print "return value " ; s
end

with this:

print "return value " ; test(10)
end
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Apr 2003 17:13
The assumption you made is that the variable you have defined is global...but it ain't. Keep the following in mind...

1. Variables cannot be used in functions unless they are passed in as an argument.

2. Variables passed in as arguments and changed are not passed back to the calling statement

3. Functions can only return one value.

The code above from FlashingBlade is the definitive way to do it...get your head around the syntax because it will be the basis of every function you ever write, and you will no doubt write hundreds in the months to come.

I hope this helps.

Thanks in advance.
All the Best,
StevieVee
Shadow
22
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 18th Apr 2003 17:44
Well explained.
alanuk
21
Years of Service
User Offline
Joined: 25th Mar 2003
Location: United Kingdom
Posted: 18th Apr 2003 22:31
Thanks guys for excellent exlanations. Now I know x-d

regards Alan
alanuk
21
Years of Service
User Offline
Joined: 25th Mar 2003
Location: United Kingdom
Posted: 18th Apr 2003 22:34
The x-d should have a smilie - oh well.

Alan

Login to post a reply

Server time is: 2024-11-24 11:11:58
Your offset time is: 2024-11-24 11:11:58