Solved

VB5 source editor add-in?

Posted on 1998-02-23
5
222 Views
Last Modified: 2011-10-03
I would like to create a menu-item or function-button (or like) that would work within the VB5 editor.  For example... the user could highlight a variable or string in their source code (in VB5 editor)... then execute a function that could insert a new line of code (following the highlighted string).  The new line of code would contain the highlighted string.

Does anyone have example code that does anything like this (in part or in whole)?

p.s. I already know how to programmatically edit the source code outside of the VB5 editor.  
0
Comment
Question by:alanl
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:shogi
Comment Utility

To access the main menu of the Visual Basic window, you can use:

VBInstance.CommandBars.Item(1)

This expression returns an object of type
Office.CommandBarControl

To Add menu-item, here an example for you how to add to the Edit menu "My Item"

Dim MyItem as Office.CommandBarControl
Dim i as Integer

For i=1 to _
VBInstance.CommandBars.Item(1).Controls("Edit").Controls.Count

  If _
VBInstance.CommandBars.Item(1).Controls("Edit").Control(i).Caption = "My Item" then
      Exit Sub
  End If
Next

Set MyItem = _
VBInstance.commandBars.Item(i).controls("Edit").Controls.Add(1,,,1)

MyItem.Caption = "My Item"

End Sub


I hope that it'll help you !!!





0
 

Author Comment

by:alanl
Comment Utility
Thanks for answering half of the question... but how can detect text selection and insert a new line of text into the source edit window?
0
 
LVL 2

Accepted Solution

by:
shogi earned 200 total points
Comment Utility
I don't know how to detect text selection in CodeModule I don't see any search on text selection.  But you can try to inverstigate in  ...CodeModule.Methode.????

For insert a new line :

VBInstance.ActiveVBProject.VBComponents.Item(1).CodeModule.InsertLine LineNumbre, TEXT

In help file you have:
Application.VBE.CodePanes(1).CodeModule.InsertLines 1, "Option Explicit"

=================================
Other methods you have in CodeModule Object are
DeleteLines(startLine,count)
InsertLine(lineNumber, codeLine)
ReplaceLine(lineNumber, codeLine)
Find()
CreateEventProc(eventName, objectName)

The basic properties of the CodeModule Object are
CountOfDeclarationLines
CountOfLines
Lines(startLine, count)
ProcBodyLine(procedureName, procedureType)
ProcCountLines(procedureName, procedureType)
ProcStartLine(procedureName,procedureType)
ProcOfLine(Line, procedureType)
=====================================

The number of code components in a project component is given by the following expresion:

VBInstance.ActiveVBProject.VBComponents.Item(1).CodeModule.Members.Count

This is the number of items in the Members collection.  To access each code component, you must access a specific item of the collection and read its Type property.  The full expression is

VBInstance.ActiveVBProject.VBComponents.Item(1).CodeModule.Members.Item(i).Type

Regards
0
 

Author Comment

by:alanl
Comment Utility
Thanks for all of your effort.
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Bought This Question.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now