Home > Articles > Programming > Visual Basic

📄 Contents

  1. A Debugging Headache
  2. Easier Debugging with Line Numbers
  • Print
  • + Share This
Like this article? We recommend

Easier Debugging with Line Numbers

The Erl function returns the line number of the last line of code to execute before the error was raised (or 0, if the method contains no line numbers.) Listing 3 illustrates how you could use line numbers and the Erl function to narrow down the source of an error 429.

Listing 3: Class_Initialize Code in Which It Is Easier to Narrow Down Where an Error Is Coming From

Private Sub Class_Initialize()
 Dim ErNum, ErDesc, ErSrc

 On Error GoTo ErrHandler
10 Set m_FormStr = CreateObject("FPIWebForms.CConCat")
20 Set FPIFormInfo = CreateObject("FPIFormInfo.CFormInfo")
30 Set FPIctrl = CreateObject("FPIFormInfo.CControlInfo")
40 Set FPIininfo = CreateObject("FPIInputInfo.CInputTableInfo")
50 Set InSymTab = CreateObject("FPISymTab.CSymTab")
  Set FPIininfo.setSymTab = InSymTab
  InSymTab.AliasPrefix = "in_"
60 FPIininfo.Initialize_CSymTabArray
70 Set CM = CreateObject("FPIClientMgr.CClientMgr")
80 Set CalcSymTab = CreateObject("FPISymTab.CSymTab")
  CalcSymTab.AliasPrefix = "ca_"
  CalcSymTab.InitializeSymbolTable 1000
90 Set DataSymTab = CreateObject("FPISymTab.CSymTab")
  DataSymTab.AliasPrefix = "da_"
  DataSymTab.InitializeSymbolTable 1000
100 Set Calc = CreateObject("FPIEval.CCalc")
110 Set Util = CreateObject("FPIUtility.CUtility")
  Util.SuppressUI = True
120 Set Eval = CreateObject("FPIEval.CEval")
  Set Eval.InputInfo = FPIininfo
  Set Eval.CalcRef = Calc
  Set Eval.Utility = Util
  Eval.AddSymbolTable DataSymTab
  Eval.AddSymbolTable CalcSymTab
  Eval.AddSymbolTable InSymTab
Exit Sub
 ErNum = Err.Number
 ErDesc = Err.Description
 ErSrc = Err.Source & ", CFormHTML.Class_Initialize"
 Err.Raise ErNum, ErSrc, ErDesc & " Line: " & Erl
End Sub

In this code, the error handler is using the Erl function to append the line number to the error message, making it much easier to narrow down the source of the error. Obviously, I'm not necessarily advocating using line numbers to the extent demonstrated in this code—and certainly not using them all the time. However, line numbers and the Erl function are effective tools for tracking down this kind of error.

  • + Share This
  • 🔖 Save To Your Account