Solved

VB5 source editor add-in?

Posted on 1998-02-23
5
252 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
[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
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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
Course of the Month8 days, 19 hours left to enroll

617 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