Post by sarossell on Feb 24, 2020 1:28:57 GMT -5
So Commodore had a clever shortcut method of handling input choices using the "ON" command. Here's a simple example:
10 INPUT A
20 ON A GOSUB 100,200,300
30 GOTO 10
100 PRINT "ONE" : RETURN
200 PRINT "TWO" : RETURN
300 PRINT "THREE" : RETURN
Each of the line numbers after the GOSUB are numbered from 1 to 3. If you enter anything else, it ignores it and just moves on to line 30.
I thought this was kind of clever and decided to try to replicate it in LB. Just out of curiosity, I tried typing it in exactly as it was. I knew it wouldn't work, but what the heck, LB can still use line numbers in a pinch. And sure enough, it choked on line 20. No surprise there.
So how can I approximate this function in LB?
My first obvious approach was this:
20 gosub word$("100,200,300",a)
Seems legit, right? Well, not so much.
I tried it without the commas.
I tried adding label brackets in clever ways.
I tried adding VAL in front of WORD$ to try to change each word into a line number.
And I even tried to assign a string variable that included label brackets:
myLabel$ = "[" + word$("100,200,300",a) + "]" : gosub myLabel$
Nope.
Bottom line, GOSUB expects a bracketed label or a line number. Period.
So, I was relegated to using either:
if choice = 1 then gosub [one] : goto [done]
if choice = 2 then gosub [two] : goto [done]
if choice = 3 then gosub [three] : goto [done]
gosub [nope]
or...
select case choice
case 1
gosub [one]
case 2
gosub [two]
case 3
gosub [three]
case else
gosub [nope]
end select
But it just seemed like I was missing something obvious.
I wonder what happens if you use ON ERROR, have a GOSUB that doesn't make sense and produces an error, and then use the trapped error to GOTO the same location and sneak a RESUME in there somewhere. What happens when it hits the RETURN for the original GOSUB?
Then my brain literally exploded and I had to go to the bathroom all of a sudden.
How's that for tryin' to sneak up on yourself?
So I'm guessing you just can't GOTO or GOSUB to a computed location. Or did I miss something? Any ideas?
:@)