ON ... GOSUB, ON ... GOTO, ON ... CALL statement
Purpose: These are control flow statements that will branch to a line label or subroutine depending on the value of a number.
Syntax 1: ON Number GOSUB ListSyntax 2: ON Number GOTO ListSyntax 3: ON Number CALL List Parameters:
|
Example 1:
GLOBAL i INPUT "Enter one number, 1, 2, or 3. " , i ON i CALL Sub_one, Sub_two, Sub_three ON i GOSUB One, Two, Three ON i GOTO Label_One, Label_Two, Label_Three END ' To stop the program from flowing to the code below Label_One: PRINT "Label One" END Label_Two: PRINT "Label Two" END Label_Three: PRINT "Label Three" END One: PRINT "Subroutine One" RETURN Two: PRINT "Subroutine Two" RETURN Three: PRINT "Subroutine Three" RETURN SUB Sub_one PRINT "SUB One" END SUB SUB Sub_two PRINT "SUB Two" END SUB SUB Sub_three PRINT "SUB Three" END SUB
Result:
Enter one number, 1, 2, or 3. 3 SUB Three Subroutine Three Label Three
Example 2:
GUI "TestApp" SUB FORMLOAD GLOBAL Form1 AS CONTROL Form1 = BCX_FORM("Test Application") BCX_BUTTON("Test button #1", Form1, 201, 10, 10) ' <<<<< Ctrl = 201 BCX_BUTTON("Test button #2", Form1, 202, 10, 60) ' <<<<< Ctrl = 202 BCX_BUTTON("Test button #3", Form1, 203, 10, 110) ' <<<<< Ctrl = 203 CENTER(Form1) SHOW(Form1) END SUB BEGIN EVENTS SELECT CASE CBMSG CASE WM_COMMAND IF CBCTLMSG = BN_CLICKED THEN '******************************************************* DIM RAW i = CBCTL-200 '<<< ctrl 201,202,203 ->> 1,2,3 ON i CALL OnClick1(i), OnClick2(i), OnClick3(i) '******************************************************* END IF END SELECT END EVENTS SUB OnClick1(a) '<< Shows using a parameter MSGBOX("Hello from click" + STR$(a)) END SUB SUB OnClick2(a) '<< Shows using a parameter MSGBOX("Hello from click" + STR$(a)) END SUB SUB OnClick3(a) '<< Shows using a parameter MSGBOX("Hello from click" + STR$(a)) END SUB
BCX Console Sample Programs using ON ... GOSUB, ON ... GOTO, ON ... CALL function.