How to GOTO a label outside the current SUB???

I have a simple problem because i want to go to a label inside a sub, and the label is in the Main Module and Qbasic returns me an error. I will give an example:
------Example.bas---------
DECLARE SUB Teste

ini: ' <=========== This is the label
PRINT "This is the initial point of this program!"
CALL Teste

SUB Teste
PRINT "THIS IS A SUB!"
GOTO ini
END SUB
-------------------------------------------
When I trie to run this program in Qbasic it returns me the error: "Label not defined", because I guess Qbasic can't Goto labels outside a Sub
can someone help me

Comments

  • sorry, that's not possible. Because, well..... Qbasic can't Goto labels outside a Sub.
    But I'm sure there's some other way to get your program to do whatever you were really wanting it to do........

    is there some reason you think you need to? maybe I can help you redesign your program...

    : I have a simple problem because i want to go to a label inside a sub, and the label is in the Main Module and Qbasic returns me an error. I will give an example:
    : ------Example.bas---------
    : DECLARE SUB Teste
    :
    : ini: ' <=========== This is the label
    : PRINT "This is the initial point of this program!"
    : CALL Teste
    :
    : SUB Teste
    : PRINT "THIS IS A SUB!"
    : GOTO ini
    : END SUB
    : -------------------------------------------
    : When I trie to run this program in Qbasic it returns me the error: "Label not defined", because I guess Qbasic can't Goto labels outside a Sub
    : can someone help me
    :
    :

  • : sorry, that's not possible. Because, well..... Qbasic can't Goto labels outside a Sub.
    : But I'm sure there's some other way to get your program to do whatever you were really wanting it to do........
    :
    : is there some reason you think you need to? maybe I can help you redesign your program...
    :
    : : I have a simple problem because i want to go to a label inside a sub, and the label is in the Main Module and Qbasic returns me an error. I will give an example:
    : : ------Example.bas---------
    : : DECLARE SUB Teste
    : :
    : : ini: ' <=========== This is the label
    : : PRINT "This is the initial point of this program!"
    : : CALL Teste
    : :
    : : SUB Teste
    : : PRINT "THIS IS A SUB!"
    : : GOTO ini
    : : END SUB
    : : -------------------------------------------
    : : When I trie to run this program in Qbasic it returns me the error: "Label not defined", because I guess Qbasic can't Goto labels outside a Sub
    : : can someone help me
    : :
    : :
    :
    :

  • : : sorry, that's not possible. Because, well..... Qbasic can't Goto labels outside a Sub.
    : : But I'm sure there's some other way to get your program to do whatever you were really wanting it to do........
    : :
    : : is there some reason you think you need to? maybe I can help you redesign your program...
    : :
    : : : I have a simple problem because i want to go to a label inside a sub, and the label is in the Main Module and Qbasic returns me an error. I will give an example:
    : : : ------Example.bas---------
    : : : DECLARE SUB Teste
    : : :
    : : : ini: ' <=========== This is the label
    : : : PRINT "This is the initial point of this program!"
    : : : CALL Teste
    : : :
    : : : SUB Teste
    : : : PRINT "THIS IS A SUB!"
    : : : GOTO ini
    : : : END SUB
    : : : -------------------------------------------
    : : : When I trie to run this program in Qbasic it returns me the error: "Label not defined", because I guess Qbasic can't Goto labels outside a Sub
    : : : can someone help me
    : : :
    : : :
    : :
    : :
    :
    :
    =============================================

    You could do this:
    ' Put this in the beginning of you program
    ' The Shared function will pass the value of "SomeVariable" from Sub
    ' to Main Program

    Dim shared SomeVariable
    SomeVariable = 0
    ini: ' <=========== This is the label

    ' just to see if this works
    x = x + 1
    PRINT "Been here"; x; "times."
    Teste
    SELECT CASE SomeVariable
    CASE 1
    GOTO ini
    CASE ELSE
    END SELECT

    Print "Not RESTARTING"


    SUB Teste

    PRINT "THIS IS A SUB!"
    PRINT
    PRINT "Do you want to start Again?"
    YN$ = INPUT$(1)

    SELECT CASE LCASE$(YN$)
    CASE "y"
    SomeVariable = 1
    CASE ELSE
    SomeVariable = 0
    END SELECT
    END SUB




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories