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 / question about functions

Author
Message
nnndohh
18
Years of Service
User Offline
Joined: 12th Aug 2006
Location: netherlands
Posted: 7th Jan 2007 22:09
i'am reading hands on darkbasic pro
at the moment i'm at chapter 7 and doing activity 7.18.

when i am at the end of the activity and read the aswers at the end of the chapter i see this.

Rem Project: testsmallest
Rem Created: 7-1-2007 21:06:13

Rem ***** Main Source File *****

input "enter first number : ",n1
while n1 <> -99
input "enter second number : ",n2
input "enter third number : ",n3

print "the smallest value is ",smallest(n1,n2,n3)
input "enter first number : ",n1
endwhile


wait key
end





function smallest(no1,no2,no3)
if no1 < no2 and no1 < no3
result = no1
else
if no2 <no1 and no2 < no3
result = no2
else
result = no3
endif
endif

print result

endfunction

but when i run the program i get an error .
'user function 'smallest' must return a value if used in an expression at line 11'
it has something to do with the line below

print "the smallest value is ",smallest(n1,n2,n3)

what is wrong about it? can't i call a function this way?the book says yes
is this an error in the book?
Lucifer
18
Years of Service
User Offline
Joined: 26th Dec 2005
Location:
Posted: 7th Jan 2007 22:17
i tested it in dbc, didnt get any errors...


i like pancakes..
Zlatan
17
Years of Service
User Offline
Joined: 2nd Jan 2007
Location: Italy
Posted: 8th Jan 2007 03:17
try after print to do a space and then open the ""
i mean:
Print"etc..."<---error
Print "etc.." not

try it

- Story Designer
- Character designer
- World designer
nnndohh
18
Years of Service
User Offline
Joined: 12th Aug 2006
Location: netherlands
Posted: 8th Jan 2007 16:04
doesn't make any difference, it still gives me this error
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Jan 2007 16:40 Edited at: 8th Jan 2007 16:48
The error is in the book. Alter the Endfunction line to:

Endfunction Result

In some languages - like Delphi, Result is an implied return value and is available on return from a function even if you haven't declared it.

In DBP you need to implicitly state the variable to return - in this case the variable 'Result'.

TDK_Man

nnndohh
18
Years of Service
User Offline
Joined: 12th Aug 2006
Location: netherlands
Posted: 8th Jan 2007 20:36
thank you , i had to know this cause it was mentioned earlier in the book but not in this listing

Login to post a reply

Server time is: 2024-09-25 15:30:46
Your offset time is: 2024-09-25 15:30:46