Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label Not Defined ERROR

Status
Not open for further replies.

pya

Technical User
Dec 18, 2020
40
AU
Hi Mikrom,

After a long time I am trying to code with Subroutines.

I get Error: Label Not Defined on Line 145 but not on 95.
Why should this be?
And what is the error trying to tell me?
And how do I get rid of it?

Thanx for your help.

pya
 
 https://files.engineering.com/getfile.aspx?folder=ea3dc779-658d-482e-aabc-c434124669e2&file=TEMP_Conversion_SUB_v2.0.txt
You mean GOSUB and GOTO. There isn't a sub named 300. I'm post-line numbers so, I might be wrong.
 
Gents,

I checked again and rectified the error.

Although the conversion from Celsius to Fahrenheit and back is a simple calculation, one of my objectives is to keep learning through coding and invoking new functionality e g CASE SELECT, something which I had never heard of.

pya
 
 https://files.engineering.com/getfile.aspx?folder=a74cca15-d135-465c-aeba-b6a15ab764d2&file=TEMP_Conversion_SUB_v2.0.txt
I'm a huge proponent of SELECT CASE. The main advantage is speed. In a SELECT, the condition is evaluated once, then jumps to the appropriate case whereas with an ELSEIF, each condition is evaluated! Take your code for example (sorry, I don't do line numbers :) and thus almost never use GOSUB or GOTO so this code may not compile but the notion is still conveyed)

Code:
SELECT CASE N
    CASE 1 : GOSUB FAHRENHEIT
    CASE 2 : GOSUB CELSIUS
    CASE 3 : GOSUB KELVIN
    CASE ELSE : PRINT "Incorrect Choice !! "  
END SELECT
N is evaluated once and jumps to the appropriate answer. Also, notice the colon :)). It separates commands.

Code:
IF N = 1 THEN 
    GOSUB FAHRENHEIT
ELSEIF N = 2 THEN
    GOSUB CELSIUS
ELSEIF N = 3 THEN
    GOSUB KELVIN
ELSE
    PRINT "Incorrect Choice !! "  
END IF
N is evaluated 3 times.
 
In QB64 you have a comfortable editor, so line numbering is unnecessary. It just makes the program less clear and harder to maintain.
 
Thank you mikrom and Geates for your help.
I am constantly learning through this forum.

pya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top