Author |
Topic: GOTO Problem (Read 828 times) |
|
Cheemag
New Member
member is offline
Posts: 16
|
|
GOTO Problem
« Thread started on: Feb 14th, 2015, 2:39pm » |
|
Hello again so soon,
This routine misbehaves in that the last line refuses to goto [Start]. The programme terminates there. The other two goto [Start] instances do in fact go back to [Start] but not the last one. Why?
[Start] cls:e=0:locate 2,7rint"Locate Auth......A" locate 2,9rint"Decode Call......D" locate 2,11rint"# to Exit" g$=input$(1):g$=lower$(g$):if g$=chr$(13) or g$="#" then cls:end if g$<>"a"and g$<>"d"then e=5 if e=5 then playwave"Chord.wav",async:goto [Start] if g$="d"then call Decode fn$:goto [Start]
open fn$ for input as#1:input#1,i for y=1 to i:input#1,a$:a$(y)=a$:next:close #1
locate 2,2rint"Auth .....Choose up to Three" for y=1 to i:locate 2,y+3rint a$(y):nextrintrint" Any Key for Menu" g$=input$(1):goto [Start]
Regards,
Cheemag
|
|
Logged
|
Regards,
Cheemag
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: GOTO Problem
« Reply #1 on: Feb 14th, 2015, 2:54pm » |
|
on Feb 14th, 2015, 2:39pm, Cheemag wrote:The other two goto [Start] instances do in fact go back to [Start] but not the last one. Why? |
|
It works for me. If I delete the file-reading lines (I don't have the file) pressing A causes "Auth .....Choose up to Three" to be printed and then pressing any key restarts. So I don't know why it doesn't work for you, but have you tried using the debugger?
I expect you are aware that your code is poorly structured. That is your choice, but it makes fault-finding more difficult, particularly for other people.
When listing code in a post please put it in a [code] block, so it is not mangled by the forum software.
Richard.
|
|
Logged
|
|
|
|
Cheemag
New Member
member is offline
Posts: 16
|
|
Re: GOTO Problem
« Reply #2 on: Feb 14th, 2015, 3:35pm » |
|
on Feb 14th, 2015, 2:54pm, Richard Russell wrote:It works for me. If I delete the file-reading lines (I don't have the file) pressing A causes "Auth .....Choose up to Three" to be printed and then pressing any key restarts. So I don't know why it doesn't work for you, but have you tried using the debugger? |
|
It works for me if I take the file reads and filenames out. I haven't yet had the course on using the debugger.
Quote:I expect you are aware that your code is poorly structured. |
|
Of course it's poorly structured - I'm a novice.
I'll try re-writing it.
Regards,
Cheemag
PS It runs in LB !
|
|
Logged
|
Regards,
Cheemag
|
|
|
Cheemag
New Member
member is offline
Posts: 16
|
|
Re: GOTO Problem
« Reply #3 on: Feb 14th, 2015, 5:19pm » |
|
on Feb 14th, 2015, 3:35pm, Cheemag wrote:
No matter whether I stick with the for/next or use while/wend, as long as the second last line with the locate and the print a$(y) is present, it will not run as intended as an LBB compile.
I've had to arrange that it runs in LB.
Regards,
Cheemag
|
|
Logged
|
Regards,
Cheemag
|
|
|
Richard Russell
Administrator
member is offline
Posts: 1348
|
|
Re: GOTO Problem
« Reply #4 on: Feb 14th, 2015, 5:51pm » |
|
on Feb 14th, 2015, 5:19pm, Cheemag wrote:as long as the second last line with the locate and the print a$(y) is present, it will not run as intended as an LBB compile. |
|
I cannot reproduce that. Please copy-and-paste this program, exactly as shown, into LBB v2.86 and compile it to an exe:
Code:[Start]
cls:e=0:locate 2,7:print"Locate Auth......A"
locate 2,9:print"Decode Call......D"
locate 2,11:print"# to Exit"
g$=input$(1):g$=lower$(g$):if g$=chr$(13) or g$="#" then cls:end
if g$<>"a"and g$<>"d"then e=5
if e=5 then playwave"Chord.wav",async:goto [Start]
if g$="d"then call Decode fn$:goto [Start]
'open fn$ for input as#1:input#1,i
'for y=1 to i:input#1,a$:a$(y)=a$:next:close #1
locate 2,2:print"Auth .....Choose up to Three"
for y=1 to i:locate 2,y+3:print a$(y):next:print:print" Any Key for Menu"
g$=input$(1):goto [Start] Now run the executable and press A followed by any other key. Here, it behaves as I would expect. What happens when you try it?
If you enable the file-reading code be very careful to ensure your strings contain no 'non-printing' characters (e.g. codes in the range 0-31). LB4 tends to ignore such characters, but in LBB they are control characters that can have all sorts of unwanted (or wanted!) effects.
Quote:I've had to arrange that it runs in LB. |
|
I am confident that it runs correctly in LBB.
Richard.
|
|
Logged
|
|
|
|
Cheemag
New Member
member is offline
Posts: 16
|
|
Re: GOTO Problem
« Reply #5 on: Feb 15th, 2015, 11:52am » |
|
on Feb 14th, 2015, 5:51pm, Richard Russell wrote:I cannot reproduce that. Please copy-and-paste this program, exactly as shown, into LBB v2.86 and compile it to an exe:
Code:[Start]
cls:e=0:locate 2,7:print"Locate Auth......A"
locate 2,9:print"Decode Call......D"
locate 2,11:print"# to Exit"
g$=input$(1):g$=lower$(g$):if g$=chr$(13) or g$="#" then cls:end
if g$<>"a"and g$<>"d"then e=5
if e=5 then playwave"Chord.wav",async:goto [Start]
if g$="d"then call Decode fn$:goto [Start]
'open fn$ for input as#1:input#1,i
'for y=1 to i:input#1,a$:a$(y)=a$:next:close #1
locate 2,2:print"Auth .....Choose up to Three"
for y=1 to i:locate 2,y+3:print a$(y):next:print:print" Any Key for Menu"
g$=input$(1):goto [Start] Now run the executable and press A followed by any other key. Here, it behaves as I would expect. What happens when you try it?
If you enable the file-reading code be very careful to ensure your strings contain no 'non-printing' characters (e.g. codes in the range 0-31). LB4 tends to ignore such characters, but in LBB they are control characters that can have all sorts of unwanted (or wanted!) effects.
I am confident that it runs correctly in LBB.
Richard. |
|
It does, but the same code does not run when incorporated in the whole programme.
It's something to do with the array a$(). As soon as that print a$(y) line is put in, it will print a$(y), but fail the GOTO.
I'll try putting it in a subroutine.
Regards,
Cheemag
|
|
Logged
|
Regards,
Cheemag
|
|
|
|