473,388 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Event handling and code line numbers

Hi All,
I have wrote a sub to record events from within the database. A lot of
these events are errors. The sub has the module name and function/sub name
passed to it to record to the table. My problem is that a lot of the subs
within the modules are quite large so haveing the module name and procedure
name points me in the right direction but I would like to be able to record
which line of code has produced the error.

Is this possible?

TIA,

Mark
Apr 20 '07 #1
3 3069
Hi Mark,

One trick that I do is as follows:

Private Sub someSub()
Dim s1 As String
On Error GoTo ErrLbl
s1 = "pos1"
...
some code
...
s1 = "pos2"
...
more code
...
s1 = "pos3"
...
yet more code
...
Exit Sub
ErrLbl:
MsgBox "Error at " & s1 & " " & Err.Message
End Sub

I set a position marker -- Dim s1 As String
If the procedure errors out, s1 will tell you after what position the
procedure errored out at. This narrows down where the errant code is
located. If the error message is
"Error at pos1 - ....' then you know the proc bombed out at the
beginning. "Error at pos2..." the problem occured after s1 = "pos2"
because the code executed normally to that point, and so on. You can
set as many positions as you want. Not real sophisticated, but it helps
- especially when you can't step through the code like vbscript, asp,
...

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Apr 20 '07 #2
Hi Rich,
not exactly what I was hoping for but that will work. Thank you for the
suggestion.

Regards,

Mark

"Rich P" <rp*****@aol.comwrote in message
news:46*********************@news.qwest.net...
Hi Mark,

One trick that I do is as follows:

Private Sub someSub()
Dim s1 As String
On Error GoTo ErrLbl
s1 = "pos1"
..
some code
..
s1 = "pos2"
..
more code
..
s1 = "pos3"
..
yet more code
..
Exit Sub
ErrLbl:
MsgBox "Error at " & s1 & " " & Err.Message
End Sub

I set a position marker -- Dim s1 As String
If the procedure errors out, s1 will tell you after what position the
procedure errored out at. This narrows down where the errant code is
located. If the error message is
"Error at pos1 - ....' then you know the proc bombed out at the
beginning. "Error at pos2..." the problem occured after s1 = "pos2"
because the code executed normally to that point, and so on. You can
set as many positions as you want. Not real sophisticated, but it helps
- especially when you can't step through the code like vbscript, asp,
..

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Apr 21 '07 #3
Hi Mark,

There is an "undocumented" function: Erl()
that will return an offending line number (provided your code uses line
numbering)

.... I know what you're thinking ... "You mean I have to go back through ALL
of my code and insert line numbers!!!???" <Roll eyes>
Well ... "Yes and No." <grin>

Have a look at this link to a "Code Comment Builder Wizard" that you CAN use
to automatically generate line numbers.
http://www.mvps.org/access/modules/mdl0031.htm

OK, OK ... I know ... we're going back to having our code look like it was
written in 1980 ... but it should work. <grin>

PS.

I also kind of fooled around with some of the Module properties ..."Lines",
"CountOfLines"
.... but I can't seem to find a way to "merge" both ideas.
It would be nice to be able to record the actual line of text as well as the
line number, right?

===================================
The majority of this is copied / pasted from Help (I just added the line
that prints whatever is on the 6th line of the selected module):
===================================
Option Compare Database
Option Explicit

Function ModuleLineTotal(strModuleName As String)
Dim mdl As Module

' Open module to include in Modules collection.
DoCmd.OpenModule strModuleName
' Return reference to Module object.
Set mdl = Modules(strModuleName)
' Print number of lines in module.
Debug.Print "Number of lines: ", mdl.CountOfLines
' Print number of declaration lines.
Debug.Print "Number of declaration lines: ", _
mdl.CountOfDeclarationLines
Debug.Print mdl.Lines(6, 1) 'Print whatever is on the 6th line of code
End Function
===================================
From the Debug Window to show usage and results:
===================================

ModuleLineTotal("modBrowseFolder")
Number of lines: 57
Number of declaration lines: 34
'This code was originally written by Terry Kreft.

(The "BrowseFolder" API can be found here:
http://www.mvps.org/access/api/api0002.htm)
if you want to see that the 6th line was indeed "'This code was originally
written by Terry Kreft."

--
--
HTH,
Don
=============================
E-Mail (if you must) My*****@Telus.net

Disclaimer:
Professional PartsPerson
Amateur Database Programmer {:o)

I'm an Access97 user, so all posted code samples are also Access97- based
unless otherwise noted.

================================================== ========================
"Mark" <mr*******@btinternet.comwrote in message
news:ds******************************@bt.com...
Hi All,
I have wrote a sub to record events from within the database. A lot of
these events are errors. The sub has the module name and function/sub name
passed to it to record to the table. My problem is that a lot of the subs
within the modules are quite large so haveing the module name and
procedure name points me in the right direction but I would like to be
able to record which line of code has produced the error.

Is this possible?

TIA,

Mark

Apr 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
2
by: Marcia Gulesian | last post by:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or later (Windows) but not when run in Safari (Mac) <body onkeypress="javascript:keysuppress(event)" > function...
2
by: Julia Baresch | last post by:
Hi everyone, As some of you may know, we've been having trouble with an unrecognized database format error. Today I installed an unfinished project on the workstation of one of my users. ...
7
by: Spacen Jasset | last post by:
The main two desirable things I feel error handling should provide are these: 1) Debugging and diagnostic aid 2) User feedback One method that is used a fair amount it to 'say' that all...
2
by: Rick Ingham | last post by:
Can anyone point me to an open source library for handling packed decimal numbers from C? I'm looking to be able to integrate Cobol and C modules that both deal with p15 and P19 packed decimal...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
12
by: sam | last post by:
hi all, i'm starting to put together a program to simulate the performance of an investment portfolio in a monte carlo manner doing x thousand iterations and extracting data from the results. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.