IonicWind Software

Creative Basic => Console Programs => Topic started by: GWS on November 30, 2010, 09:58:58 AM

Title: Sub call from another sub's return
Post by: GWS on November 30, 2010, 09:58:58 AM
Hi folks,

I've not seen this before .. I wonder if it has any uses ?  ::)


openconsole
def once:int
Once = 0

While inkey$ = ""
    If Once = 0
        FuncOne()
    EndIf
endwhile

closeconsole

end

sub FuncOne()
    print( "Function One!" )
return FuncTwo()

sub FuncTwo()
    print( "Function Two!" )
    Once = 1
return


Is it any different from calling 'FuncTwo' from the body of  'FuncOne' ?

best wishes, :)

Graham

Title: Re: Sub call from another sub's return
Post by: LarryMc on November 30, 2010, 10:27:02 AM
In the code that I just posted for sapero there is a function that has a
return function() line in it.

LarryMc
Title: Re: Sub call from another sub's return
Post by: GWS on November 30, 2010, 10:53:21 AM
Well so there is ..  :o

What a coincidence .. I found my converted example on another website ..  :)

How on earth did you come up with your usage Larry ?  I thought a 'return' could only handle a single value.

I wasn't even sure it would 'compile' .. but it did ..  ;D

best wishes, :)

Graham
Title: Re: Sub call from another sub's return
Post by: Egil on November 30, 2010, 10:59:39 AM
Interesting...
Is there any special reason to enclose the strings to be printed by parentheses?

Reagards

Egil
Title: Re: Sub call from another sub's return
Post by: LarryMc on November 30, 2010, 11:12:29 AM
Quote from: GWS on November 30, 2010, 10:53:21 AM
How on earth did you come up with your usage Larry ?  I thought a 'return' could only handle a single value.
I've seen it more than once but that specific piece of code came from the old pyxia forum CD.

LarryMc
Title: Re: Sub call from another sub's return
Post by: aurelCB on November 30, 2010, 01:15:17 PM
Yeah...looks cool...
I see something similiar in some Joske example.
Here is one GUI example:
'call-func2
Def win:WINDOW
WINDOW win,0,0,400,300,@minbox,0,"MainGUI",main
SetWindowColor win,rgb(220,220,230)

Function1()

WAITUNTIL win=0
END

SUB main
SELECT @CLASS
Case @IDCLOSEWINDOW
CLOSEWINDOW win
ENDSELECT
RETURN

SUB Function1()
'
Return Function2()

SUB Function2
CONTROL win,"B,SET,50,100,121,25,0x50000000,1"
Return
Title: Re: Sub call from another sub's return
Post by: GWS on November 30, 2010, 04:33:27 PM
Hmm .. I'd not noticed it before ..  :)

Well spotted Egil, I hadn't fully 'translated' the example .. CB version would be ..


openconsole
cls

FuncOne()

do:until inkey$<>""
closeconsole
end

sub FuncOne()
    print "Function One!"
return FuncTwo()

sub FuncTwo()
    print "Function Two!"
return


But I'm not sure how it differs from how I would normally have coded it ..


openconsole
cls

FuncOne()

do:until inkey$<>""
closeconsole
end

sub FuncOne()
print "Function One!"
FuncTwo()
return

sub FuncTwo()
print "Function Two!"
return


Unless there is some useful reason to use 'Return' for this purpose, it seems to be venturing into the obscure ..  :P

You have a good memory Aurel .. Trust Joske to turn up something unusual ..  :)
I wonder where he's got to .. I miss his contributions ..  ;D

best wishes,

Graham

Title: Re: Sub call from another sub's return
Post by: Egil on December 01, 2010, 05:42:48 AM
Well, I asked because your example works equally well with or without the parentheses. Usually any "deviation" from what's "normal", mean something special. so I just had to ask. :)