VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Add User Initials to a block of selected text

by Ustes (6 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (5 Votes)

If you have to add your username or initals tag to each change you make in code, this lets you select a block of text and add it to the end of each line.

Assumes
add this code to the mnuHandler_Click
Side Effects
It doesn't delete any old comments that were there.

Rate Add User Initials to a block of selected text


'this event fires when the menu is clicked in the IDE
Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  
  Dim MyPane As CodePane
  Dim lngStartLine As Long
  Dim lngEndLine As Long
  Dim lngStartCol As Long
  Dim lngEndCol As Long
  Dim strLine As String
  Dim tmpLine As String
  Dim i As Integer
  Dim LineLengths() As Integer
  Dim intLongestLine As Integer
  Dim intTotalLines As Integer
  Dim intLinecount As Integer
  Dim intDiff As Integer
    
  If strUser = "" Then
    strUser = "'"
    strUser = strUser & InputBox("Enter User Initials.", "Block Initials")
    strUser = strUser & " - " & Format(Now, "mm/dd/yy hh:mm")
  End If
  
  Set MyPane = VBInstance.ActiveCodePane
  MyPane.GetSelection lngStartLine, lngStartCol, lngEndLine, lngEndCol
  
  intTotalLines = lngEndLine - lngStartLine
  
  ReDim LineLengths(intTotalLines)
  intLinecount = 0
  
  For i = lngStartLine To lngEndLine - 1
    strLine = MyPane.CodeModule.Lines(i, 1)
    If intLongestLine < Len(strLine) Then
      LineLengths(intLinecount) = Len(strLine)
      intLongestLine = LineLengths(intLinecount)
    End If
    intLinecount = intLinecount + 1
  Next i
  
  
  For i = lngStartLine To lngEndLine - 1
    strLine = MyPane.CodeModule.Lines(i, 1)
    tmpLine = strLine
    If Trim(tmpLine) <> "" Then
      intDiff = intLongestLine - Len(strLine)
      MyPane.CodeModule.ReplaceLine i, strLine & Space(intDiff + 5) & strUser
    End If
  Next i
  
  
  
End Sub

Download this snippet    Add to My Saved Code

Add User Initials to a block of selected text Comments

No comments have been posted about Add User Initials to a block of selected text. Why not be the first to post a comment about Add User Initials to a block of selected text.

Post your comment

Subject:
Message:
0/1000 characters