News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

ON x GoTo, doesn't work in a Proc

Started by keytapper, Aug 05, 2022, 12:51 PM

Previous topic - Next topic

keytapper

Hi forum
I noticed that inserting a On GoToL in a procedure will not be able to find the labels where to jump to.
My case is a particular condition that imposed me to reduce the nested level of subroutines. So I put all calls into the main procedure, but the sequence of parsing a procedure seems to leave out the internal labels.
Device 16F628A
Xtal 20
Declare Hserial_Baud 9600

Dim myvar As Byte
myvar = TestGoto(3)
HSerOut ["myvar is ", Dec myvar]
End

Proc TestGoto(invar As Byte), Byte
  If invar < 4 Then
   On invar GoTo answer1,answer2,answer,3
  End If
answer1:
  Result = invar * 3
  ExitProc
answer2:
  Result = invar * 7
  ExitProc
answer3:
  Result = invar * 2
EndProc
Error is
Error at Line [11]      In file [X:\\test.bas]  *** Label 'ANSWER' not found! ***
The other way around is to use a SELECT/ENDSELECT which able to find the labels.
Ignorance comes with a cost

diebobo

Typo in this part : answer,3 musn't be answer3 ?

keytapper

#2
The snippet may have different labels, I suppose they'll fail as well.
This is after corrections
Device 16F628A
Xtal 20
Declare Hserial_Baud 9600

Dim myvar As Byte
myvar = TestGoto(3)
HSerOut ["myvar is ", Dec myvar]
End
Proc TestGoto(invar As Byte), Byte
  If invar < 4 Then
   On invar GoTo first,second,third
  End If
first:
  Result = invar * 3
  ExitProc
second:
  Result = invar * 7
  ExitProc
third:
  Result = invar * 2
EndProc
And now is exactly what I seen before
Error[113]   X:\\\A.S 1400 : Symbol not previously defined (FIRST)
Error[113]   X:\\\A.S 1401 : Symbol not previously defined (SECOND)
Error[113]   X:\\\A.S 1402 : Symbol not previously defined (THIRD)
ASSEMBLER ERRORS. HEX file not Created

Thank you, Diebobo,  to have spotted my typo.
Ignorance comes with a cost