Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB5 source editor add-in?

Posted on 1998-02-23
5
Medium Priority
?
261 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 600 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

927 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