PC Review


Reply
Thread Tools Rate Thread

Determining Line Number

 
 
Bob Day
Guest
Posts: n/a
 
      4th Sep 2003
VS 2003, vb.net...

Is there a way to determine the line number currently executing in your
code, so you can log this line number information (e.g. via trace)?

Thanks!

Bob Day


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Sep 2003
"Bob Day" <(E-Mail Removed)> schrieb:
> VS 2003, vb.net...
>
> Is there a way to determine the line number currently
> executing in your code, so you can log this line number
> information (e.g. via trace)?


You can set error numbers by hand:

\\\
Public Sub Bla()
1: Dim i As Integer
2: i = 2
3 Dim s As String = "Hello World"
End Sub
///

When using 'On Error...' error handlers, you can determine the line number
by reading the 'Erl' property of the 'Err' object.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      4th Sep 2003
"Herfried K. Wagner [MVP]" <(E-Mail Removed)> schrieb:
> 3 Dim s As String = "Hello World"


Sorry, the line above should read "3: Dim s As String = "Hello World"".

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      4th Sep 2003
Hi Bob,

The following will give you the line number of your code (as in the source
file):

Dim CurrentStack As System.Diagnostics.StackTrace
MsgBox (CurrentStack.GetFrame(0).GetFileLineNumber)

In case you're interested, you can find out about the routine that you're
in as well as all its
callers.

Public Function MeAndMyCaller As String
Dim CurrentStack As New System.Diagnostics.StackTrace
Dim Myself As String = CurrentStack.GetFrame(0).GetMethod.Name
Dim MyCaller As String = CurrentStack.GetFrame(1).GetMethod.Name
Return "In " & Myself & vbCrLf & "Called by " & MyCaller
End Function

This can be very handy if you want a generalised error routine because it
can get the name of the caller (which would be where the error occurred).

Regards,
Fergus


 
Reply With Quote
 
Bob Day
Guest
Posts: n/a
 
      22nd Sep 2003
Good question. yes, I am running in debug mode. The only thing I could
find on "Program Debug Symbols" in help was:
"To access the Debug Symbol Files property page, right-click on your
Solution in Solution Explorer and choose Properties from the shortcut menu.
Expand the Common Properties folder and click the Debug Symbol Files page. "

However, the "Debug Symbol Files" does not appear as an option as it says it
should above. I presume that means I some how heave it turned off. I don't
see where to turn it on. Where do you turn it on?

Please advise. Thanks for your help.

Bob Day

"Herfried K. Wagner [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> "Bob Day" <(E-Mail Removed)> schrieb:
> > Howver, using the code you suggest below in various situations always
> > returns a line number of zero
> > > Dim CurrentStack As System.Diagnostics.StackTrace
> > > MsgBox (CurrentStack.GetFrame(0).GetFileLineNumber)

>
> Do you run your application in Debug mode? 'GetFileLineNumber' is only
> avaliable if Program Debug symbols are available for the application.
>
> --
> Herfried K. Wagner
> MVP · VB Classic, VB.NET
> http://www.mvps.org/dotnet
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
determining slide number and object/shape number Candace Microsoft Powerpoint 4 6th May 2008 03:52 PM
Determining the line number in XML source Pavils Jurjans Microsoft Dot NET Framework 0 9th Oct 2006 05:30 PM
determining line numbers upon error JohnR Microsoft VB .NET 2 10th Aug 2006 02:23 PM
VB Code line for determining column k483 Microsoft Excel Misc 2 22nd Jun 2004 06:57 PM
Determining Row Number Wes Jester Microsoft Excel Programming 2 26th Aug 2003 09:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:55 AM.