Rx_
Nothing In Moderation
- Local time
- Yesterday, 23:35
- Joined
- Oct 22, 2009
- Messages
- 2,803
MZ Tools is a free add-in that offers a Toolbar in VBA Editor - Add / Remove Line Number.
In my first version of BASIC in ROM on an Ohio Scientific single board computer (pre-dates Atari, Apple, and other PC) the 6502 Processor and BASIC required Line Numbers. One bad habit was to use a GOTO (Line Number).
The Line Numbers are not common to code today. For troubleshooting, they can play a valuable role.
In my first version of BASIC in ROM on an Ohio Scientific single board computer (pre-dates Atari, Apple, and other PC) the 6502 Processor and BASIC required Line Numbers. One bad habit was to use a GOTO (Line Number).
The Line Numbers are not common to code today. For troubleshooting, they can play a valuable role.
Code:
Public Sub ErrorTrapUsingLineNumbers()
Dim dblNumer As Double
Dim dblRandomNumber As Double
Dim MyAnswer As Long
10 On Error GoTo Hell
' A Random Crash to make it more dynamic is perscribed by Rx_
' Note: all random numbers will cause an error when divided by zero
' Howerver the randoem number will cause the error to oxxur at a different line number
' In VBA Editor window - A tool such as MZ Tools adds a Tool box with Add / Remove Line Numbers
' A developer can manuall add line numbers. They must be acending and not duplicates
20 dblRandomNumber = Rnd()
30 Select Case dblRandomNumber
Case Is < 0.3
40 MyAnswer = 3 / 0
50 Case Is < 0.5
60 MyAnswer = 5 / 0
70 Case Is < 0.6
81 MyAnswer = 6 / 0 ' line numbers don't have to end in 0
90 Case Is < 0.9
100 MyAnswer = 9 / 0
110 Case Else
120 MyAnswer = 10 / 0
130 End Select
140 MsgBox MyAnswer, vbCritical, "Error prevents this from ever executing"
150 Exit Sub
' Code that finishes is above, bad code goes below
Hell:
160 MsgBox "Value: " & dblRandomNumber & vbCrLf & _
"Error Line: " & Erl & vbCrLf & _
"Error: (" & Err.Number & ") " & Err.Description, vbCritical, "Line Number where code caused Error"
End Sub