September 26, 2020, 06:03:35 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Labels in cb

Started by TexasPete, May 08, 2010, 05:50:37 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TexasPete

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:

Code Select

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



TexasPete

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

aurelCB

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.
forum for hobby programming:<br />https://aurelsoft.ucoz.com

TexasPete

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

aurelCB

here is one quickly written example:

Code Select
'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
forum for hobby programming:<br />https://aurelsoft.ucoz.com