QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: lemonskunnk on January 31, 2020, 12:57:03 pm
-
Hello all,
I'm new to the QB64 world and am working to move an older quickbasic program to QB64 (As I imagine most here are...)
Anyway, the error that is impeding my ability to complete the conversion is "Common Label within a SUB/FUNCTION on XX Line" which is occurring on ALL "ON ERROR GOTO X" statements. The error occurs with both text and numbered goto's.
I'm sure some more contextual information will be helpful - whatever you need, just ask.
Any help would be greatly appreciated.
Thanks,
Dan
-
EDIT: Sorry, On Error requires a GOTO so forget what I had here.
Doesn't make sense to me, you should never use a GOTO to somewhere outside a sub. But neither do I use it, rather anticipate and head off errors before they happen.
-
On error goto label requires a label to exist in the main module, where error handling will happen. It seems you have multiple identical labels in multiples subs. You must concentrate error handling under one common label in the main module (before any subs).
-
Error trapping works with labels or numbers. As Fell just pointed out, the trap needs to be in the main module. If your's is not, meaning it or any number of them is in a sub, just cut and paste them into the main module.
Here is an example, just don't press ENTER when you get the "Press any key to continue prompt." I usually make my own key input routines, but I noticed I that ENTER will remain in the key buffer, even after the RUN statement is processed. I don't know if LINE INPUT responded the same way in QBasic, or not. It reminded me that QB64 may still need some debug work in regard to the RUN statement.
Anyway, here we go...
PRINT "Select type of error statement to test..." PRINT "[0] End routine..."
PRINT "Sorry, that was not an acceptable response. Take a time out. :D :D :D"
100
PRINT "Error:";
ERR;
"Press any key to resume..."
error_trap:
PRINT "Error:";
ERR;
"Press any key to resume..."
LOCATE 10000, 10000 ' Not possibe! PRINT:
PRINT "Test with line number trap completed. One moment..."
LOCATE 10000, 10000 ' Not possibe! PRINT:
PRINT "Test with label completed. One moment..."
If you need more help, just post the code.
Pete
-
Thanks for all the input. I was unaware that the error traps must all the concentrated in one Module - the program is coming from the original quick basic and it uses "ON LOCAL ERROR GOTO X" so there are 10's of error traps all throughout all modules and subs.
Anyway, I will make a concentrated error trap that handles all error cases for the whole module and let you know how it goes!
Thanks,
Dan
-
You can do it. I had 14 QB programs I combined into one QB64 program and I took all those individual error traps and combined them into one error trap. You may need to use a global variable to tell the error trap how to proceed, such as when a RESUME NEXT, RESUME [Line Number] or a RESUME 0 should be used. If you are not familiar with RESUME 0, it means go back to the line that threw the error. Anyway, good luck, and let us know how it turns out.
Pete