Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default How can I create an error log?

How would I create an error log that would store log data to a cell range or
a .txt file, to include: Error number, error name/description, line of
suspected erronious code and if possible some basic information about what
they did to create that error?

I am having some intermittent errors that occur in my VB code on different
machines... Because no one else at my office has any idea what I'm doing
they disregard the error and move on. Then all I get is the extremely useful
error report from them: "Your excel file doesn't work!" which is very hard to
debug!

Any help or suggestions on implementing this would be appreciated.

Thank you!

~Josh
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default How can I create an error log?

http://tinyurl.com/q65ae

--
Regards,
Tom Ogilvy


"Bob the Kart Racing fool" wrote:

How would I create an error log that would store log data to a cell range or
a .txt file, to include: Error number, error name/description, line of
suspected erronious code and if possible some basic information about what
they did to create that error?

I am having some intermittent errors that occur in my VB code on different
machines... Because no one else at my office has any idea what I'm doing
they disregard the error and move on. Then all I get is the extremely useful
error report from them: "Your excel file doesn't work!" which is very hard to
debug!

Any help or suggestions on implementing this would be appreciated.

Thank you!

~Josh

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default How can I create an error log?

See if something like this suits you:


Sub test()

Dim bt As Byte
Dim btSum As Byte
Dim arrErrorData(1 To 6)

10 On Error GoTo ERROROUT

20 For bt = 1 To 300
30 btSum = btSum + bt
40 Next

50 Exit Sub
ERROROUT:

60 arrErrorData(1) = Format(Now, "dd/mmm/yyyy hh:mm")
70 arrErrorData(2) = "Module: Module1"
80 arrErrorData(3) = "Procedu Sub test()"
90 arrErrorData(4) = "Error line: " & Erl
100 arrErrorData(5) = "Error number: " & Err.Number
110 arrErrorData(6) = Err.Description

120 Save1DArrayToTextAppend "C:\ErrorqqLog.txt", arrErrorData

End Sub


Sub Save1DArrayToTextAppend(txtFile As String, _
arr As Variant, _
Optional LB As Long = -1, _
Optional UB As Long = -1)

Dim r As Long
Dim hFile As Long

If LB = -1 Then
LB = LBound(arr)
End If

If UB = -1 Then
UB = UBound(arr)
End If

hFile = FreeFile

Open txtFile For Append As hFile

For r = LB To UB
If r = UB Then
Write #hFile, arr(r)
Else
Write #hFile, arr(r);
End If
Next

Close #hFile

End Sub


Just copy and paste in a module and run the Sub test.


RBS


"Bob the Kart Racing fool"
wrote in message ...
How would I create an error log that would store log data to a cell range
or
a .txt file, to include: Error number, error name/description, line of
suspected erronious code and if possible some basic information about what
they did to create that error?

I am having some intermittent errors that occur in my VB code on different
machines... Because no one else at my office has any idea what I'm doing
they disregard the error and move on. Then all I get is the extremely
useful
error report from them: "Your excel file doesn't work!" which is very hard
to
debug!

Any help or suggestions on implementing this would be appreciated.

Thank you!

~Josh


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default How can I create an error log?

Amazing!!! I'm really impressed! Thank you so much! I will just have the
log file saved to my network drive so I can access it from my computer and do
"check ups" on my program!!

"RB Smissaert" wrote:

See if something like this suits you:


Sub test()

Dim bt As Byte
Dim btSum As Byte
Dim arrErrorData(1 To 6)

10 On Error GoTo ERROROUT

20 For bt = 1 To 300
30 btSum = btSum + bt
40 Next

50 Exit Sub
ERROROUT:

60 arrErrorData(1) = Format(Now, "dd/mmm/yyyy hh:mm")
70 arrErrorData(2) = "Module: Module1"
80 arrErrorData(3) = "Procedu Sub test()"
90 arrErrorData(4) = "Error line: " & Erl
100 arrErrorData(5) = "Error number: " & Err.Number
110 arrErrorData(6) = Err.Description

120 Save1DArrayToTextAppend "C:\ErrorqqLog.txt", arrErrorData

End Sub


Sub Save1DArrayToTextAppend(txtFile As String, _
arr As Variant, _
Optional LB As Long = -1, _
Optional UB As Long = -1)

Dim r As Long
Dim hFile As Long

If LB = -1 Then
LB = LBound(arr)
End If

If UB = -1 Then
UB = UBound(arr)
End If

hFile = FreeFile

Open txtFile For Append As hFile

For r = LB To UB
If r = UB Then
Write #hFile, arr(r)
Else
Write #hFile, arr(r);
End If
Next

Close #hFile

End Sub


Just copy and paste in a module and run the Sub test.


RBS


"Bob the Kart Racing fool"
wrote in message ...
How would I create an error log that would store log data to a cell range
or
a .txt file, to include: Error number, error name/description, line of
suspected erronious code and if possible some basic information about what
they did to create that error?

I am having some intermittent errors that occur in my VB code on different
machines... Because no one else at my office has any idea what I'm doing
they disregard the error and move on. Then all I get is the extremely
useful
error report from them: "Your excel file doesn't work!" which is very hard
to
debug!

Any help or suggestions on implementing this would be appreciated.

Thank you!

~Josh



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default How can I create an error log?

No trouble. 2 further tips:
If you have to add this to a lot of procedures then you could make a central
error writing Sub with a few arguments and save yourself a lot of typing.
Secondly get MZ-Tools as that can quickly add the error lines for you + has
lots of other good things:
http://www.mztools.com/index.htm

RBS

"Bob the Kart Racing fool"
wrote in message ...
Amazing!!! I'm really impressed! Thank you so much! I will just have
the
log file saved to my network drive so I can access it from my computer and
do
"check ups" on my program!!

"RB Smissaert" wrote:

See if something like this suits you:


Sub test()

Dim bt As Byte
Dim btSum As Byte
Dim arrErrorData(1 To 6)

10 On Error GoTo ERROROUT

20 For bt = 1 To 300
30 btSum = btSum + bt
40 Next

50 Exit Sub
ERROROUT:

60 arrErrorData(1) = Format(Now, "dd/mmm/yyyy hh:mm")
70 arrErrorData(2) = "Module: Module1"
80 arrErrorData(3) = "Procedu Sub test()"
90 arrErrorData(4) = "Error line: " & Erl
100 arrErrorData(5) = "Error number: " & Err.Number
110 arrErrorData(6) = Err.Description

120 Save1DArrayToTextAppend "C:\ErrorqqLog.txt", arrErrorData

End Sub


Sub Save1DArrayToTextAppend(txtFile As String, _
arr As Variant, _
Optional LB As Long = -1, _
Optional UB As Long = -1)

Dim r As Long
Dim hFile As Long

If LB = -1 Then
LB = LBound(arr)
End If

If UB = -1 Then
UB = UBound(arr)
End If

hFile = FreeFile

Open txtFile For Append As hFile

For r = LB To UB
If r = UB Then
Write #hFile, arr(r)
Else
Write #hFile, arr(r);
End If
Next

Close #hFile

End Sub


Just copy and paste in a module and run the Sub test.


RBS


"Bob the Kart Racing fool"

wrote in message
...
How would I create an error log that would store log data to a cell
range
or
a .txt file, to include: Error number, error name/description, line of
suspected erronious code and if possible some basic information about
what
they did to create that error?

I am having some intermittent errors that occur in my VB code on
different
machines... Because no one else at my office has any idea what I'm
doing
they disregard the error and move on. Then all I get is the extremely
useful
error report from them: "Your excel file doesn't work!" which is very
hard
to
debug!

Any help or suggestions on implementing this would be appreciated.

Thank you!

~Josh




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Just create it regardless with error handling Bob Phillips Excel Discussion (Misc queries) 3 September 27th 07 06:23 PM
Need to create a error message box lostinformulas Excel Worksheet Functions 4 July 12th 06 04:40 PM
create chart error '1004' .. Daniel Excel Programming 4 October 6th 05 01:23 AM
error trying to create excel macro fun4peg Excel Programming 1 January 13th 04 10:18 PM
MAPI create object error Dim Excel Programming 0 November 24th 03 07:08 PM


All times are GMT +1. The time now is 02:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"