• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

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?
0
clapper100497
Asked:
clapper100497
1 Solution
 
daffyduck14milCommented:
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
 
sridhar_PJCommented:
Dear clapper,

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

Netminder
CS Moderator
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now