Solved

I want to know which line in the code is executed

Posted on 2001-08-02
4
144 Views
Last Modified: 2010-05-02
I am using VB6 SP5.
I want to show on a label a module name & line number that is currently executed in my app.
Any ideas?
0
Comment
Question by:clapper100497
4 Comments
 
LVL 3

Accepted Solution

by:
daffyduck14mil earned 100 total points
Comment Utility
Hi,

As far as i know, you can't do that while your code is executed. What you can do however, is set the caption of a label at every start of a sub or function. But, mind me asking, why would you want to do that? If your answer is Error handling or bug tracking then you can do something else:

Open a new project, put a command button on it, and paste this in your code:

Private Sub Command1_Click()
' =============================================================
' Module Type : Form
' Module Name : Form1
' Object      : Command1
' Proc Type   : Sub
' Proc Name   : Click
' Scope       : Private
' Author      :
' Date        : 01/01/97 00:00
' Taken from  : "Advanced Visual Basic" book
'
' History     : 01/01/97 00:00: Peter J. Morris : Original Code.
' =============================================================

' Set up general error handler.
On Error GoTo Error_In_Command1_Click:

1  Dim sErrorDescription As String

2  Const sProcSig = "frmMain Command1_click" 'MODULE_NAME & "Command1_Click"

       ' ========== Body Code Starts ==========

3  Debug.Print FileLen("c:\temp\filethatdoesnotexist.txt")

       ' ========== Body Code Ends ==========

4  Exit Sub

' Error handler
Error_In_Command1_Click:

5  With Err
6      sErrorDescription = "Error '" & .Number & " " & _
       .Description & "' occurred in " & sProcSig & _
       IIf(Erl <> 0, " at line " & CStr(Erl) & ".", ".")
7  End With

8  Select Case MsgBox(sErrorDescription, _
                      vbAbortRetryIgnore, _
                      App.Title & " Error")

       Case vbAbort
9      Resume Exit_Command1_Click:
10     Case vbRetry
11         Resume
12     Case vbIgnore
13         Resume Next
14     Case Else
15         End

16  End Select

Exit_Command1_Click:

End Sub

When you run this, and push the button, you get an error message, stating what line and what module. Thus in turn, you need to number the code.

How this works: the Erl variable is a undocumented variable. It takes the linenumber of the current line of code, _if_ it's numbered.

Might not be what you need, but enjoy never the less.

Grtz.&copy;

D.
0
 
LVL 3

Expert Comment

by:sridhar_PJ
Comment Utility
Dear clapper,

what daffyduck14mil says is right. There is no option to show line number of module name in vb
Regards
Sridhar
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi clapper,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept daffyduck14mil's comment(s) as an answer.

clapper, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now