Posts: 6
Threads: 2
Joined: Jan 2024
Reputation:
0
I'm kind of not even sure how to phrase this question. _ERRORLINE will display the line where and error is found. But say I wanted to use the command to display something different depending on where the error is found. As in bounding the error to within a section of code, as in:
If _ErrorLine > 100and _ErrorLine < 150 Print "This section of code"
If _ErrorLine > 200and _ErrorLine < 250 Print "This other section of code"
Well, that is good, so long as I don't add more code prior to these two lines, in which case I have to keep tabs on those lines and change them each time I add or subtract prior code. Is there an ability to 'tag' something to use in place of the values? Or, maybe a different command.....
Posts: 3,978
Threads: 177
Joined: Apr 2022
Reputation:
220
01-25-2024, 12:16 AM
(This post was last modified: 01-25-2024, 12:36 AM by bplus.)
How about line labels?
Nah, no way to connect line numbers to labels. Never liked line numbers.
Could use a trip wire variable, every time the code execution passes a certain point the trip wire variable is increased by 1. Probably not good inside loops and for main code only. Report the trip wire value and you can track down where the error occured
But why isn't exact line number in source code not helpful?
Read the Wiki, _errorline reports the exact line number in the source code that you can see from the IDE.
Also, On Error can be set for different conditions and turned off. So change that according to the message you want to make for section of code that it's covering.
b = b + ...
Posts: 2,697
Threads: 327
Joined: Apr 2022
Reputation:
217
Section$ = "Header"
Code
Code
Code
Code
Code
Code
Section$ = "Middle"
Code
Code
Code
Code
Code
Section$ = "End"
....
PRINT "Error occurred after Section:": Section$
Posts: 6
Threads: 2
Joined: Jan 2024
Reputation:
0
Here is an example:
1 On Error GoTo FAULT
2
3 '------------------------------------------------------------------------------
4 DTE1: 'Send Date to COM5
5 A$ = Date$
6 Put #1, , A$
7 STATLINE$ = Date$ + " - " + Time$ + " - COM5 Date Request"
8 GoSub EVENTSAVE
9 GoSub PRINTSTAT
10 Return
11 '------------------------------------------------------------------------------
12 TME1: 'Send Time to COM5
13 A$ = Time$
14 Put #1, , A$
15 STATLINE$ = Date$ + " - " + Time$ + " - COM5 Time Request"
16 GoSub EVENTSAVE
17 GoSub PRINTSTAT
18 Return
19 '------------------------------------------------------------------------------
20
21 FAULT:
22 If _ErrorLine = 9 Print "Unable to print Date"
23 Resume
24
25
Now, if I add a bunch of code prior to Line 9, the an error occurring from that line of code will no longer print because the line number changed. That line of code is now line 11.
1 On Error GoTo FAULT
2
3 Screen 0, 1: Width 80: Color 2, 0
4 KEY Off: Cls: Close
5 '------------------------------------------------------------------------------
6 DTE1: 'Send Date to COM5
7 A$ = Date$
8 Put #1, , A$
9 STATLINE$ = Date$ + " - " + Time$ + " - COM5 Date Request"
10 GoSub EVENTSAVE
11 GoSub PRINTSTAT
12 Return
13 '------------------------------------------------------------------------------
14 TME1: 'Send Time to COM5
15 A$ = Time$
16 Put #1, , A$
17 STATLINE$ = Date$ + " - " + Time$ + " - COM5 Time Request"
18 GoSub EVENTSAVE
19 GoSub PRINTSTAT
20 Return
21 '------------------------------------------------------------------------------
22
23 FAULT:
24 If _ErrorLine = 9 Print "Unable to print Date"
25 Resume
I hope that makes sense......
Posts: 128
Threads: 12
Joined: Apr 2022
Reputation:
14
01-25-2024, 02:36 PM
(This post was last modified: 01-25-2024, 02:43 PM by mdijkens.)
For these kind of things I would always use ERR:
Code: (Select All)
FAULT:
'https://qb64phoenix.com/qb64wiki/index.php/ERROR_Codes
Select Case Err
Case 52 'Bad file name or number
Print "Could not access serial"
Case 68 'Device unavailable
Print "Could not open serial"
Case Else
Print "Unknown error"; Err; " on line"; _ErrorLine
End Select
Resume Next
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience