GLBasic forum

Main forum => GLBasic - en => Topic started by: Gerfy on 2009-Aug-18

Title: Gosub or Function
Post by: Gerfy on 2009-Aug-18
Hi,

Newbie just being a newbie.. could someone please tell me the difference of using a gosub rather than just a function ?
From what I understand, both can do the same thing.

Really starting to relax and enjoy this program, I'm quite a reasonable programmer.. and I'm impressed with what I've played with so far. (Just needs some good examples/demos - hopefully I can help out once I've found my feet)

Knew keeping those old spectrum basic programming books would come in handy ;)

Thanks.
Title: Re: Gosub or Function
Post by: Moru on 2009-Aug-18
Just forget about Gosub, use functions. Gosub can't handle the passing of parameters but takes just as long to call so there is no real reason for gosub other than backwards compatibility with older basics.
Title: Re: Gosub or Function
Post by: Gerfy on 2009-Aug-18
thought so.. cant seem to work out how to pass a return for more than one variable though ?

return x,y

doesnt seem to work.
Title: Re: Gosub or Function
Post by: MrTAToad on 2009-Aug-18
Thats where you use BYREF to modify the passed variable.
Title: Re: Gosub or Function
Post by: Gerfy on 2009-Aug-18
Thanks. will have a play
Title: Re: Gosub or Function
Post by: D2O on 2009-Aug-19
Quote from: Gerfy on 2009-Aug-18
thought so.. cant seem to work out how to pass a return for more than one variable though ?

return x,y

doesnt seem to work.

Sorry for bad English ;)

You can use Type.
Example:
Code (glbasic) Select

GLOBAL giveme AS Tgivemore

giveme = f_givemore()

PRINT giveme.a$,10,10
PRINT giveme.b#,10,30
PRINT giveme.c%,10,50


SHOWSCREEN
KEYWAIT


//-----------------------------




FUNCTION f_givemore AS Tgivemore :

LOCAL temp AS Tgivemore

temp.a$ = "Hello"
temp.b# = 12.0012
temp.c% = 999


RETURN temp

ENDFUNCTION

TYPE Tgivemore

a$
b#
c%

ENDTYPE