Emulating GOTO and GOSUB from line-numbered BASICs from 1970’s and 1980’s

I’m working on changing a simple line-number BASIC program to one that will run into XOJO (REALbasic).

Here’s what I’ve done so far (you’ll have to add three TextFields for the example below).

(1) Start with the line-number BASIC program (let’s assume that the word “GOTO” is not optional in the starting program):

120 REM Greatest Common Divisor

130 Dim Number1, Number2, Quotient, Remainder As Single

140 Number1 = Val ( TextFIeld1.Text )

150 Number2 = Val ( TextFIeld2.Text )

160 Quotient = Floor ( Number1 / Number2 )

170 R = Number1 - Quotient * Number2

180 Number1 = Number2

190 Number2B = Remainder

200 If Remainder > 0 Then GOTO 160

210 TextField3.Text = Str (Number1 )

(2) If you see a “GOTO” followed by a line number, change that line number to “L” plus the line number.

120 REM Greatest Common Divisor

130 Dim Number1, Number2, Quotient, Remainder As Single

140 Number1 = Val ( TextFIeld1.Text )

150 Number2 = Val ( TextFIeld2.Text )

160: Quotient = Floor ( Number1 / Number2 )

170 R = Number1 - Quotient * Number2

180 Number1 = Number2

190 Number2 = Remainder

200 If Remainder > 0 Then GOTO L160

210 TextField3.Text = Str (Number1 )

(3) Find that same line number elsewhere in the program at the beginning of a line. If you have not already done so, change the line number to “L” plus the line number plus colon, and put the rest of that line on a brand-new line: Repeat as needed.

120 REM Greatest Common Divisor

130 Dim Number1, Number2, Quotient, Remainder As Single

140 Number1 = Val ( TextFIeld1.Text )

150 Number2 = Val ( TextFIeld2.Text )

160:

Quotient = Floor ( Number1 / Number2 )

170 Remainder = Number1 - Quotient * Number2

180 Number1 = Number2

190 Number2B = Remainder

200 If Remainder > 0 Then GOTO L160

210 TextField3.Text = Str (Number1 )

For simple programs, that should be all you need to do to handle GOTO.

Now for two questions: (1) What code would need to be used to handle GOSUB? (A simple sample progran would be great!) (2) Am I correct in assuming that the line numbers in line-number BASIC programs are essentially only used for GOTO and GOSUB?

Barry Traver