Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating VB Add-in

Posted on 1998-12-10
1
Medium Priority
?
250 Views
Last Modified: 2008-02-20
I often have the need to reverse code around an = sign. For example:
ClassField = txtClassField
to
txtClassField = ClassField

Does anyone have an Add-in that will do this for whatever is selected in the code window?  If not, can anyone tell me the event in the add-in to put the code under (I was thinking a hot-key could trigger it) and the code that lets me reference what is selected in the Code Window.
0
Comment
Question by:MichaelJC
[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
1 Comment
 
LVL 14

Accepted Solution

by:
waty earned 200 total points
ID: 1449268
As I am finishing the VBIDEUtils add-ins, and release very soon, I think I will add this feature.

You have to add it under a button or in the menu in the Edit

Here is part of my add-ins

Private Sub SetupEditMenus()
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 17/09/1998
   ' * Time             : 22:06
   ' * Module Name      : clsConnect
   ' * Module Filename  : clsConnect.cls
   ' * Procedure Name   : SetUpEditMenus
   ' * Parameters       :
   ' **********************************************************************
   ' * Comments         : Adds the menus to the VBE Edit menu and sets up the
   ' * objects to trap the command bar events for the new controls
   ' *
   ' *
   ' **********************************************************************

   Dim ctlBar        As CommandBarControl
   Dim ctlMenu       As CommandBarPopup
   Dim ctlMenu2      As CommandBarPopup
   Dim nI            As Integer

   ' *** Ignore errors, so we can set objects, then check if they were set OK
   On Error Resume Next

   ' *** Get the VBE Main menu bar
   Set ctlBar = VBInstance.CommandBars(1).FindControl(msoControlPopup, 30003)

   ' *** Find our pop-up menu
   Set ctlMenu2 = ctlBar.Controls(msVBIDEUTILS)

   ' *** If not found, we need to create our menus
   If ctlMenu2 Is Nothing Then

      ' *** Look for the "Insert File" menu item, so we can add ours above it
      For nI = 1 To ctlBar.Controls.count
         If ctlBar.Controls(nI).Id = 14 Then Exit For
      Next

      'Add our popup menu
      Set ctlMenu2 = ctlBar.Controls.Add(Type:=msoControlPopup, before:=nI + 1, temporary:=True)
      ctlMenu2.Caption = msVBIDEUTILS

      'Now add the submenus for our indenting menu items
      With ctlMenu2.Controls
         With .Add(Type:=msoControlButton, Parameter:="Proc", temporary:=True)
            .Caption = msMENU_PROC
            .FaceId = 2564
         End With

         With .Add(Type:=msoControlButton, Parameter:="Mod", temporary:=True)
            .Caption = msMENU_MOD
            .FaceId = 472
         End With

         With .Add(Type:=msoControlButton, Parameter:="Proj", temporary:=True)
            .Caption = msMENU_PROJ
            .FaceId = 2557
         End With

         With .Add(Type:=msoControlButton, Parameter:="ModuleHeader", temporary:=True)
            .Caption = msMENU_MODULE_HEADER
            ' *** Copy the icon to the clipboard
            Clipboard.SetData LoadResPicture(101, 0)
           
            ' *** Set the icon for the button
            .PasteFace
            DoEvents
         End With

         With .Add(Type:=msoControlButton, Parameter:="ProcHeader", temporary:=True)
            .Caption = msMENU_PROC_HEADER
            ' *** Copy the icon to the clipboard
            Clipboard.SetData LoadResPicture(102, 0)
           
            ' *** Set the icon for the button
            .PasteFace
            DoEvents
         End With

         With .Add(Type:=msoControlButton, Parameter:="CommentOut", temporary:=True)
            .Caption = msMENU_COMMENT_OUT
            ' *** Copy the icon to the clipboard
            Clipboard.SetData LoadResPicture(103, 0)
           
            ' *** Set the icon for the button
            .PasteFace
            DoEvents
         End With

         With .Add(Type:=msoControlButton, Parameter:="UnComment", temporary:=True)
            .Caption = msMENU_UNCOMMENT
            ' *** Copy the icon to the clipboard
            Clipboard.SetData LoadResPicture(104, 0)
           
            ' *** Set the icon for the button
            .PasteFace
            DoEvents
         End With

         With .Add(Type:=msoControlButton, Parameter:="ClearDebug", temporary:=True)
            .Caption = msMENU_CLEAR_DEBUG
            ' *** Copy the icon to the clipboard
            Clipboard.SetData LoadResPicture(105, 0)
           
            ' *** Set the icon for the button
            .PasteFace
            DoEvents
         End With

         With .Add(Type:=msoControlButton, Parameter:="APIError", temporary:=True)
            .Caption = msMENU_API_ERROR
            ' *** Copy the icon to the clipboard
            Clipboard.SetData LoadResPicture(106, 0)
           
            ' *** Set the icon for the button
            .PasteFace
            DoEvents
         End With
         
         With .Add(Type:=msoControlButton, Parameter:="CodeDatabase", temporary:=True)
            .Caption = msMENU_CODEDATABASE
            ' *** Copy the icon to the clipboard
            Clipboard.SetData LoadResPicture(107, 0)
           
            ' *** Set the icon for the button
            .PasteFace
            DoEvents
         End With
         
         With .Add(Type:=msoControlButton, Parameter:="Options", temporary:=True)
            .Caption = msMENU_FORM
            .FaceId = 222
         End With

      End With
   End If

   ' *** Set up the command bar event handlers for the new menu items
   With ctlMenu2
      Set vbeMenus(mnSTART_EDITMENU).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_PROC))
      Set vbeMenus(mnSTART_EDITMENU + 1).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_MOD))
      Set vbeMenus(mnSTART_EDITMENU + 2).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_PROJ))
      Set vbeMenus(mnSTART_EDITMENU + 3).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_MODULE_HEADER))
      Set vbeMenus(mnSTART_EDITMENU + 4).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_PROC_HEADER))
      Set vbeMenus(mnSTART_EDITMENU + 5).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_COMMENT_OUT))
      Set vbeMenus(mnSTART_EDITMENU + 6).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_UNCOMMENT))
      Set vbeMenus(mnSTART_EDITMENU + 7).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_CLEAR_DEBUG))
      Set vbeMenus(mnSTART_EDITMENU + 8).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_API_ERROR))
      Set vbeMenus(mnSTART_EDITMENU + 9).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_CODEDATABASE))
      Set vbeMenus(mnSTART_EDITMENU + 10).cMenu = VBInstance.Events.CommandBarEvents(.Controls(msMENU_FORM))
   End With

End Sub



And here is how I comment a line :

Public Sub BlockOutCode()
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 17/09/1998
   ' * Time             : 22:06
   ' * Module Name      : Comment_Module
   ' * Module Filename  : Comment.bas
   ' * Procedure Name   : BlockOutCode
   ' * Parameters       :
   ' **********************************************************************
   ' * Comments         : Block out a complete set of code
   ' *
   ' *
   ' **********************************************************************

   Dim nStartLine    As Long
   Dim nStartColumn  As Long
   Dim nEndLine      As Long
   Dim nEndColumn    As Long

   Dim sLine         As String
   Dim sCode         As String

   Dim nLine         As Integer

   Dim nI            As Integer

   Dim prjProject    As VBProject
   Dim cpCodePane    As CodePane

   Dim bUseTabs      As Boolean
   Dim iIndentSpaces As Integer
   Dim sIndent       As String
   
   On Error Resume Next

   ' *** Try to get the active project
   Set prjProject = VBInstance.ActiveVBProject

   ' *** If we couldn't get it, display a message and quit
   If prjProject Is Nothing Then
      MsgBox "Could not identify current project."
      Exit Sub
   End If

   ' *** Try to find the active code pane
   Set cpCodePane = VBInstance.ActiveCodePane

   ' *** If we couldn't get it, display a message and quit
   If cpCodePane Is Nothing Then
      MsgBox "Could not identify current module."
      Exit Sub
   End If
   
   cpCodePane.GetSelection nStartLine, nStartColumn, nEndLine, nEndColumn
   sCode = cpCodePane.CodeModule.Lines(nStartLine, nEndLine - nStartLine)

   If (sCode = "") Then Exit Sub

   bUseTabs = (GetSetting(gsREG_APP, "Indent", "UseTabs", "N") = "Y")
   iIndentSpaces = Val(GetSetting(gsREG_APP, "Indent", "IndentSpaces", "3"))
   If bUseTabs Then
      sIndent = String(1, miTAB)
   Else
      sIndent = String(iIndentSpaces, " ")
   End If
   
   ' *** Add lines
   nLine = nStartLine
   sLine = sIndent & "' #HOut# " & String(20, "*")
   cpCodePane.CodeModule.InsertLines nLine, sLine
   nLine = nLine + 1

   sLine = sIndent & "' #HOut# Programmer Name  : " & gsDevelopper
   cpCodePane.CodeModule.InsertLines nLine, sLine
   nLine = nLine + 1

   sLine = sIndent & "' #HOut# Date             : " & Format(Now, "Short Date")
   cpCodePane.CodeModule.InsertLines nLine, sLine
   nLine = nLine + 1

   sLine = sIndent & "' #HOut# Time             : " & Format(Now, "Short Time")
   cpCodePane.CodeModule.InsertLines nLine, sLine
   nLine = nLine + 1

   sLine = sIndent & "' #HOut# " & String(20, "*")
   cpCodePane.CodeModule.InsertLines nLine, sLine
   nLine = nLine + 1

   ' *** Comment each line
   For nI = 1 To CountLine(sCode)
      sLine = sIndent & "' #Out# " & GetLine(sCode, nI)
      cpCodePane.CodeModule.ReplaceLine nLine, sLine
      nLine = nLine + 1
   Next
   sLine = sIndent & "' #HOut# " & String(20, "*")
   cpCodePane.CodeModule.InsertLines nLine, sLine
   nLine = nLine + 1

   cpCodePane.SetSelection nLine, nStartColumn, nLine, nStartColumn

End Sub


0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Suggested Courses

610 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