473,480 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Determining Line Number

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
Nov 20 '05 #1
5 6081
"Bob Day" <Bo****@TouchTalk.net> 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
Nov 20 '05 #2
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> 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
Nov 20 '05 #3
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
Nov 20 '05 #4
Thanks for your help.

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)
Any suggestions?

Bob Day

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... 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

Nov 20 '05 #5
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]" <hi*******@m.activevb.de> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Hello,

"Bob Day" <Bo****@TouchTalk.net> 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

Nov 20 '05 #6

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

Similar topics

2
2980
by: David Abrahams | last post by:
Is there any way to determine the file and line number (if any) of a method's invocation from within its body? Many Thanks in advance, Dave -- David Abrahams Boost Consulting...
0
1479
by: Jim Cobban | last post by:
I am reading an XML file using Java. I would like to issue diagnostic messages which identify the original line number in the source, but that information does not appear to be available during a...
11
21880
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a...
9
2813
by: kangaroo | last post by:
Hi guys, when we run a stored proc and it results into an unhandled error, the error message returned by db2 udb does not contain a line number that caused an error. This makes it pretty...
2
1708
by: JohnR | last post by:
Hi, I'm looking for some advice and guidance. I have a program in vb.net and I know that when it's run and the pdb file is available that the exception will contain the line number of the error. ...
2
4749
by: johnivey | last post by:
I have a large query that I am trying to debug in query analyzer. However, the errors I get have no line number or reference to where they are failing. How can I find out what line in the query is...
7
2295
by: Daniel | last post by:
hi guys i have never understood this so i am hoping someone can help. I have had errors in my app before where on closing it down i get a NullReferenceException error thrown BUT no line number...
4
2993
by: Jeff Jarrell | last post by:
I have a block of code that during development is prone to casting errors. It is mostly a DataReader type thing. It looks something like this. _prtPNID = myDLReader.GetString("prtPNID")...
11
21146
by: Horacius ReX | last post by:
Hi, I have to search for a string on a big file. Once this string is found, I would need to get the number of the line in which the string is located on the file. Do you know how if this is...
0
7041
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
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.