?
Solved

I want to know which line in the code is executed

Posted on 2001-08-02
4
Medium Priority
?
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Accepted Solution

by:
daffyduck14mil earned 400 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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