?
Solved

Create VB 6.0 AddIn

Posted on 2007-10-10
7
Medium Priority
?
481 Views
Last Modified: 2011-09-20
Hi,

I am trying to create a VB 6.0 Addin by using VB itself

I do have 2 problems here
1. How to get the current active project, active form?
    Set p = VBInstance.ActiveVBProject
    Set c = p.VBComponents.Item("Form1") <- I could only hardcode this, but no idea how to dynamically get the current active project active form.

2. Whenever there is a button click, it will close the form.
=========================================================
Public VBInstance As VBIDE.VBE
Public Connect As Connect

Option Explicit

Private Sub CancelButton_Click()
    Connect.Hide
End Sub


Private Sub Command1_Click()
    UpdateTag
End Sub

Private Sub Form_Load()
   Dim c As VBComponent
   Dim p As VBProject
   Dim vbc As VBControl
   Dim vbf As VBForm
   Dim sc As String
   Dim sp As String
   Dim svbc As String
   
    Set p = VBInstance.ActiveVBProject
    Set c = p.VBComponents.Item("Form1")
   
    List1.Clear
   
    If c.Type = vbext_ct_VBForm Then
        c.Activate
        Set vbf = c.Designer
        For Each vbc In vbf.VBControls
            'MsgBox vbc.Properties("name")
           List1.AddItem vbc.Properties("name")
           List1.ItemData(List1.NewIndex) = IIf(IsNumeric(vbc.Properties("tag")), vbc.Properties("tag"), 0)
        Next vbc
    End If

End Sub

Private Sub UpdateTag()
   Dim c As VBComponent
   Dim p As VBProject
   Dim vbc As VBControl
   Dim vbf As VBForm
   Dim sc As String
   Dim sp As String
   Dim svbc As String
   
    Set p = VBInstance.ActiveVBProject
    Set c = p.VBComponents.Item("Form1")
   
    If c.Type = vbext_ct_VBForm Then
        c.Activate
        Set vbf = c.Designer

        For Each vbc In vbf.VBControls
            If vbc.Properties("name") = List1.List(List1.ListIndex) Then
                vbc.Properties("tag") = Text1.Text
                Exit For
            End If
   
        Next vbc
    End If

End Sub

Private Sub List1_Click()
    Text1.Text = List1.ItemData(List1.ListIndex)
End Sub


==============================================================

When I click on the command button1, it will execute the code inside, and auto close the frmAddIn.
May I know how can I make it remain open? (I didn't write any code to hide it of close it)

Thanks.

0
Comment
Question by:cybeh
  • 3
  • 3
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1500 total points
ID: 20051319
1:
with p = vbInstance.ActiveVBProject,

p.ActiveForm

returns the current active form, if any.

2:
you have this line:

c.Activate

which will activate that form. you need to "activate" your frmAddin form later back:

Private Sub Command1_Click()
    UpdateTag
    Me.Activate
End Sub


0
 
LVL 1

Author Comment

by:cybeh
ID: 20053385
1:
with p = vbInstance.ActiveVBProject,

p.ActiveForm <- Run Time Error 438. Object doesn't Support this property or method

Private Sub Command1_Click()
    UpdateTag
    Me.Activate <- Compile Error. Method or Data Not Found
End Sub
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20054320
you can loop the components:

Set p = VBInstance.ActiveVBProject
pComponents = p.VBComponents.Count

For i = 1 To pComponents
   set c = p.VBComponents.Item(i)
    If c.Type = vbext_ct_VBForm Then
        c.Activate
        etc ...
    End If
Next

looks like I found a wrong information with ActiveForm :(


for 2: it should actually be SetFocus:

Private Sub Command1_Click()
    UpdateTag
    Me.SetFocus
End Sub

0
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!

 
LVL 1

Author Comment

by:cybeh
ID: 20054341
But will it return the wrong form if that project is having more than 1 form?
0
 
LVL 1

Author Comment

by:cybeh
ID: 20054379
Just try out. It will give problem when there are more than 1 form, as it didn't check which is the "active" form. Please advice.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20054396
I found the problem...

Set c  = VBInstance.ActiveWindow
If c.Type = vbext_ct_VBForm Then
   c.Activate
End If


a nice blog about vb addins:
http://blog.csdn.net/cheneychao/archive/2006/03/20/630084.aspx
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Simple Linear Regression
Six Sigma Control Plans

839 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