I want to know which line in the code is executed

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?
Who is Participating?
daffyduck14milConnect With a Mentor Commented:

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

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


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.


Dear clapper,

what daffyduck14mil says is right. There is no option to show line number of module name in vb
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
Per recommendation, force-accepted.

CS Moderator
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.