IonicWind Software

Creative Basic => General Questions => Topic started by: TexasPete on May 08, 2010, 05:50:37 AM

Title: Labels in cb
Post by: TexasPete on May 08, 2010, 05:50:37 AM
I am trying to us a few "goto" to tie different sections of Code together. Can the term label be used to define labels in the first part of the program and then put the labe itself in any location in the program Example:


label FirstLine
label Secondline
label ThirdLine
goto FirstLine
'===latter in the program
secondline:


'Latter inthe program
FirstLine

end



I assume the CB intends on defining the labels first and then use goto or jump to jump to the label locations in the program.

Is that right?

Texas Pete


Title: Re: Labels in cb
Post by: TexasPete on May 08, 2010, 06:01:15 AM
I have defined a label, But CB is responding with and error message of unknown type.

label Section1

Today I must be dense.

Thanks
Texas Pete
Title: Re: Labels in cb
Post by: aurelCB on May 08, 2010, 06:13:18 AM
Pete you can use Labels but you cannot call them like subs.
You must write as :
GOTO firstlabel
--------------------
------------------
LABEL firstlabel
----------------
---------------------
JUMP secondlabel
----------------
---------------------
--------------
secondlabel:
-----------
-------------
---------------
GOTO firstlabel

And dont forget that when you execute goto can't return automaticly like sub.
Title: Re: Labels in cb
Post by: TexasPete on May 08, 2010, 06:20:23 AM
Thanks Aurel,
The error message must be caused by something else. I thought I had a simple goto right off the bat. I have been using them for years.
Texas Pete
Title: Re: Labels in cb
Post by: aurelCB on May 08, 2010, 06:35:24 AM
here is one quickly written example:

'the lines program
'displays random lines forever
DEF win:window
DEF run:int
'open a window and add a menu
WINDOW win,0,0,400,300,@SIZE|@MINBOX|@MAXBOX|@CAPTION,0,"Lines",main:Setwindowcolor win,rgb(220,220,230)
run=0

LABEL start
For n=10 TO 100
For p=0 TO 100000:Next p
Line win,n,50,n,100,rgb(0,140,0)
Next n

JUMP label2

LABEL label3
For n=10 TO 100
For p=0 TO 100000:Next p
Line win,n,50,n,100,rgb(0,140,140)
Next n

JUMP label4


LABEL the_end
waituntil run=0
closewindow win
end

SUB main
SELECT @class
CASE @idclosewindow
run=0
ENDSELECT
RETURN

LABEL label2
For n=10 TO 100
For p=0 TO 100000:Next p
Line win,n,50,n,100,rgb(140,140,0)
Next n

GOTO label3

LABEL label4
For n=10 TO 100
For p=0 TO 100000:Next p
Line win,n,50,n,100,rgb(180,0,0)
Next n

GOTO the_end