Solved

VB5 source editor add-in?

Posted on 1998-02-23
5
233 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
ID: 1457764

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
ID: 1457765
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
ID: 1457766
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
ID: 1457767
Thanks for all of your effort.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1457768
Bought This Question.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

776 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