Solved

Numbering code lines and then return that line number in error handling?

Posted on 2002-07-10
4
162 Views
Last Modified: 2010-05-02
How do I number lines and then return that line number in error handling?
0
Comment
Question by:BLWWLB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7144007
in VB this is NOT possible, in VB.net this functionality is given automatically.
Sorry
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7144043
You number code lines by manually adding line numbers at the beginning of the logical line or on a blank line.  (Or you can use an app to automatically add line numbers for you.)

To reference these line numbers in the error trappign routine, use the keyword ERL, such as msgbox "Error in procedure xxx at (or after) line number " & erl
0
 
LVL 5

Expert Comment

by:rpai
ID: 7144053
You can do something like this in your code:-

Private Sub Test()
Dim x as Integer
Dim y as Integer
Dim sError as String

On Error Goto ErrHandler
  sError = ""
  sError = "Initializing x"
  x = 1
  sError = "Initializing y"
  y = 0
  sError = "Performing Division"
  x = x/y
  sError = "Printing"
  Debug.Print x
Exit Sub

ErrHandler:
  Err.Raise Err.Source, Err.Desription & vbcrlf & "Error When: " & sError, Err.Number

Exit Sub
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 50 total points
ID: 7144132
Using ERL:

private sub ErrorTest()
  ' test the error line variable
  on error goto Error_Trap

  dim a as integer
10 msgbox "starting test"
20 debug.print "will this generate an error?"
30 debug.print "how about this?" & a
   a=20
50 debug.print "or this: " & a
55 a=0.5
60 debug.print "or this: " & 5/a
70 ' line number without code
  a=0
  debug.print "or maybe this: " & a/0
  exit sub

Error_Trap:
  msgbox "Error in ErrorTest at line " & erl
  resume next
end sub

You should get an error at line 60 and line 70, but the 70-error is really two lines below.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question