Author Topic: Gosub or Function  (Read 1365 times)

Gerfy

  • Guest
Gosub or Function
« 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.
« Last Edit: 2009-Aug-18 by Gerfy »

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1773
    • View Profile
    • Homepage
Re: Gosub or Function
« Reply #1 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.

Gerfy

  • Guest
Re: Gosub or Function
« Reply #2 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.

MrTAToad

  • Guest
Re: Gosub or Function
« Reply #3 on: 2009-Aug-18 »
Thats where you use BYREF to modify the passed variable.

Gerfy

  • Guest
Re: Gosub or Function
« Reply #4 on: 2009-Aug-18 »
Thanks. will have a play

Offline D2O

  • Prof. Inline
  • *****
  • Posts: 1061
    • View Profile
    • http://www.deuteriumoxid.com
Re: Gosub or Function
« Reply #5 on: 2009-Aug-19 »
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