473,743 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ 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 6102
"Bob Day" <Bo****@TouchTa lk.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.ac tivevb.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.Diagnost ics.StackTrace
MsgBox (CurrentStack.G etFrame(0).GetF ileLineNumber)

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.Diagnost ics.StackTrace
Dim Myself As String = CurrentStack.Ge tFrame(0).GetMe thod.Name
Dim MyCaller As String = CurrentStack.Ge tFrame(1).GetMe thod.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.Diagnost ics.StackTrace
MsgBox (CurrentStack.G etFrame(0).GetF ileLineNumber)
Any suggestions?

Bob Day

"Fergus Cooney" <fi******@tesco .net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. Hi Bob,

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

Dim CurrentStack As System.Diagnost ics.StackTrace
MsgBox (CurrentStack.G etFrame(0).GetF ileLineNumber)

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.Diagnost ics.StackTrace
Dim Myself As String = CurrentStack.Ge tFrame(0).GetMe thod.Name
Dim MyCaller As String = CurrentStack.Ge tFrame(1).GetMe thod.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.ac tivevb.de> wrote in message
news:up******** ******@tk2msftn gp13.phx.gbl...
Hello,

"Bob Day" <Bo****@TouchTa lk.net> schrieb:
Howver, using the code you suggest below in various situations always
returns a line number of zero
Dim CurrentStack As System.Diagnost ics.StackTrace
MsgBox (CurrentStack.G etFrame(0).GetF ileLineNumber)


Do you run your application in Debug mode? 'GetFileLineNum ber' 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
2993
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 http://www.boost-consulting.com
0
1497
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 DOM traversal. I am using DOM rather than SAX because I want to be able to update the DOM and then write the updated XML file back out. -- Jim Cobban jcobban@magma.ca 34 Palomino Dr. Kanata, ON, CANADA
11
21929
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 C# equivalent. Any ideas? -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc. varnk@diebold.com
9
2841
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 difficult to debug those procs. Line number have always been there in Oracle messages. When I Googled on this, I saw some people showing DB2 Stored Proc error messages with line numbers in them (like LINE NUMBER=1285), which makes me believe that...
2
1730
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. Obviously when trying to track down an error this is extremely valuable. I've also heard people say that when you distribute your app, you should compile it without debug and without the pdb file. In this case the exception has no error...
2
4763
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 causing a particular error message to appear? Thanks John Ivey South Pike School District
7
2311
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 given. I have put try catch state,ents to catch it around every method that fires during shutdown and none seem to be the cause, due to the lack of line number i am literally guessing where it could be? What else can i do?
4
3005
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") _prtSKU = myDLReader.GetString("prtSKU") _prtPic = myDLReader.GetString("prtPic") _prtRsvQty = myDLReader.GetInteger("prtRsvQty")
11
21176
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 possible to do in python ? Thanks
0
8795
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9486
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9344
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9214
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8218
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6057
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4572
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3286
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 we have to send another system
2
2759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.