|
-
Jul 20th, 2007, 03:24 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Err.Number (Can it be done in .NET 2005)?
Hi all,
In VB6, you could put into an error prompt the error number using err.number. Does 2005 support doing this?
When an error occurrs in my app and I have handled the exceptions, I want to be able to display what line the error occurred on.
Please advise.
-
Jul 20th, 2007, 03:37 PM
#2
Re: Err.Number (Can it be done in .NET 2005)?
Yes, use the Exception object if you are Catching on it.
Code:
MyException.Errors.Item(0).Number.ToString
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 20th, 2007, 03:40 PM
#3
Re: Err.Number (Can it be done in .NET 2005)?
err.number is the error's ID number, not the line it occured in. This is true in VB6 and .NET.
-
Jul 20th, 2007, 03:42 PM
#4
Re: Err.Number (Can it be done in .NET 2005)?
Correct, Erl is in VB 6 the error line number object of you have line numbering in your procedure. Otherwise what I posted will get the line number in VB.NET
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 20th, 2007, 03:45 PM
#5
Re: Err.Number (Can it be done in .NET 2005)?
Rob, what am I overlooking?
exceptions don't have an errors collection, so what datatype is MyException in your example code?
-
Jul 20th, 2007, 03:59 PM
#6
Re: Err.Number (Can it be done in .NET 2005)?
Oh Snap! That was in 2003. Heres the 2005 version.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim o As Object
Try
MessageBox.Show(o.ToString)
Catch ex As Exception
Dim sMess As String = ex.StackTrace.Substring(ex.StackTrace.LastIndexOf(":"))
MessageBox.Show("Error at" & sMess)
End Try
End Sub
End Class
Now you could improve upon it and take into account that you will have multiple errors sometimes or whatever you want to do.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 20th, 2007, 04:07 PM
#7
Re: Err.Number (Can it be done in .NET 2005)?
This modification will get the first error only. The previous one was getting the last error line number when you have multiple errors.
Code:
Dim sMess As String = ex.StackTrace.Substring(ex.StackTrace.IndexOf(":", ex.StackTrace.IndexOf(":") + 1))
MessageBox.Show("Error at" & sMess)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 20th, 2007, 04:10 PM
#8
Re: Err.Number (Can it be done in .NET 2005)?
Rob for my own sanity, did the exception class in 2003 have an errors property? I don't remember that it did. I know some of the special exceptions had an errors collection, like a SQLException.
I just want to make sure my knowledge is correct
-
Jul 20th, 2007, 04:20 PM
#9
Re: Err.Number (Can it be done in .NET 2005)?
Yes, I pulled that code from one project where I was catching errors from the SQLException collection. I didnt realize they werent common to all exceptions nor in 2005.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 1st, 2007, 03:14 PM
#10
Thread Starter
PowerPoster
Re: Err.Number (Can it be done in .NET 2005)?
-
Aug 1st, 2007, 03:17 PM
#11
Re: Err.Number (Can it be done in .NET 2005)?
Yes, thats the old VB 6 Microsoft.Visualbasic class. You will have to manually add all the number lines to do it though.
Post #7 wil work without numbering..
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 1st, 2007, 03:30 PM
#12
Thread Starter
PowerPoster
Re: Err.Number (Can it be done in .NET 2005)?
 Originally Posted by RobDog888
Yes, thats the old VB 6 Microsoft.Visualbasic class. You will have to manually add all the number lines to do it though.
Post #7 wil work without numbering..
i tried that MSDN article and i added the line numbers yet it returned a line number of 0 but the err.raise was on line 8, so that definately didnt work
-
Aug 1st, 2007, 03:44 PM
#13
Thread Starter
PowerPoster
Re: Err.Number (Can it be done in .NET 2005)?
when i do:
vb Code:
"Error Line: " & ex.StackTrace.Substring(ex.StackTrace.LastIndexOf(":")) & vbNewLine & _
it shows as "Error Line: :line 22
What I would like for it to do is "Error Line: 22"
Can this be done?
 Originally Posted by RobDog888
Oh Snap! That was in 2003. Heres the 2005 version.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim o As Object
Try
MessageBox.Show(o.ToString)
Catch ex As Exception
Dim sMess As String = ex.StackTrace.Substring(ex.StackTrace.LastIndexOf(":"))
MessageBox.Show("Error at" & sMess)
End Try
End Sub
End Class
Now you could improve upon it and take into account that you will have multiple errors sometimes or whatever you want to do.
-
Aug 1st, 2007, 03:48 PM
#14
Thread Starter
PowerPoster
Re: Err.Number (Can it be done in .NET 2005)?
i did this: err.erl (and had to add line numbers) and it worked well
but then i get a ContextSwitchDeadLock error on my messagebox showing the error generated
Last edited by BrailleSchool; Aug 1st, 2007 at 03:51 PM.
-
Aug 1st, 2007, 04:01 PM
#15
Re: Err.Number (Can it be done in .NET 2005)?
Use the code from post #7. You are only using part of it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 1st, 2007, 04:08 PM
#16
Thread Starter
PowerPoster
Re: Err.Number (Can it be done in .NET 2005)?
 Originally Posted by RobDog888
Use the code from post #7. You are only using part of it.
when using that code:
it shows as "Error Line: :line 22
What I would like for it to do is "Error Line: 22"
how can I do that?
-
Aug 1st, 2007, 04:11 PM
#17
Re: Err.Number (Can it be done in .NET 2005)?
You didnt copy all of it as you are missing the "+1 )" at the end. Hence the reason for the double colons.
Copied from #7
Dim sMess As String = ex.StackTrace.Substring(ex.StackTrace.IndexOf(":", ex.StackTrace.IndexOf(":") + 1))
MessageBox.Show("Error Line: " & sMess)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 1st, 2007, 05:48 PM
#18
Thread Starter
PowerPoster
Re: Err.Number (Can it be done in .NET 2005)?
 Originally Posted by RobDog888
You didnt copy all of it as you are missing the "+1 )" at the end. Hence the reason for the double colons.
Copied from #7
even when i do that, it shows
Error Line: :line #
-
Aug 1st, 2007, 06:31 PM
#19
Re: Err.Number (Can it be done in .NET 2005)?
Its just string parsing. Seems it needs another +1 for the starting position of the returned string.
Code:
Dim sMess As String = ex.StackTrace.Substring(ex.StackTrace.IndexOf(":", ex.StackTrace.IndexOf(":") + 1) + 1)
MessageBox.Show("Error Line: " & sMess)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 1st, 2007, 06:40 PM
#20
Thread Starter
PowerPoster
Re: Err.Number (Can it be done in .NET 2005)?
adding +5 instead of +1 got rid of :line 
thanks for your help RD
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|