Gosub or Function

Previous topic - Next topic

Gerfy

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.

Moru

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.

Gerfy

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.

MrTAToad

Thats where you use BYREF to modify the passed variable.

Gerfy

Thanks. will have a play

D2O

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
I7 2600K; 8 GB RAM ; Win10 Pro x64 | NVidia GTX 750 TI 2048MB ; Realtec OnBoard Sound;
Lenovo ThinkPad T400: XP Pro
GLB Premium-immer Aktuell