Solved

VB5 source editor add-in?

Posted on 1998-02-23
5
227 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

943 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

5 Experts available now in Live!

Get 1:1 Help Now