Solved

I want to know which line in the code is executed

Posted on 2001-08-02
4
145 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
ID: 6343807
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
ID: 6343815
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
ID: 7198392
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
ID: 7213214
Per recommendation, force-accepted.

Netminder
CS Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ms access #TYPE! error on report when no data 4 65
Windows 10 start screen issues 9 51
Updates not working for MS Windows 7 12 152
Macro Excel - Multiple If conditions 2 64
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now