Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Insert Code from Addin (Re-Post with New Subject Description)

31 views
Skip to first unread message

k_zeon

unread,
May 5, 2009, 5:08:16 PM5/5/09
to
Hi

I have made a small addin to insert text into the code window and this all
works well.
What i need to do now is get the Width and height of the Form whose Code
window I am currently in (Not the Code Window width and Height but the
Form.Height and Form.Width)

ie

Form1 - Code window

Private Form_Load()

End Sub

I can insert text as follows

Private Form_Load()
StartSize...
End Sub

but would like to get the Width and Height of the Form an use this in my
text to insert ie. StartSize (5000,3000)

Private Form_Load()
StartSize (5000,3000)
End Sub


hope someone can help

thanks

Garry

Nobody

unread,
May 5, 2009, 5:19:16 PM5/5/09
to
"k_zeon" <silverm...@googlemail.com> wrote in message
news:uBS7cWcz...@TK2MSFTNGP05.phx.gbl...

I am not sure, but try VBComponent.ReadProperty.


k_zeon

unread,
May 5, 2009, 6:33:38 PM5/5/09
to
Hi

I have tried everything I can think of to get the Form Width & Height that
is in the VB6 IDE ie FORM1

I start with ' Public VBInstance As VBIDE.VBE ' in my Addin + other
code

then this is what i use to insert text ' Call
VBInstance.ActiveCodePane.CodeModule.InsertLines(1, strText) '

What I am trying to do is add the Currently Selected Form.Width and
Form.Height of the Linked Active Code Window

I have tried the suggetion of VBComponent.ReadProperty but have not gotten
it to work.

I really need to find out how this works as I dont really know enough about
Addins at the moment and only have one small book as a refernce.

many thanks

Garry

"Nobody" <nob...@nobody.com> wrote in message
news:Ow4msccz...@TK2MSFTNGP06.phx.gbl...

Nobody

unread,
May 5, 2009, 8:58:20 PM5/5/09
to
"k_zeon" <silverm...@googlemail.com> wrote in message
news:%23hj6JGd...@TK2MSFTNGP04.phx.gbl...

> Hi
>
> I have tried everything I can think of to get the Form Width & Height
> that is in the VB6 IDE ie FORM1
>
> I start with ' Public VBInstance As VBIDE.VBE ' in my Addin + other
> code
>
> then this is what i use to insert text ' Call
> VBInstance.ActiveCodePane.CodeModule.InsertLines(1, strText) '
>
> What I am trying to do is add the Currently Selected Form.Width and
> Form.Height of the Linked Active Code Window
>
> I have tried the suggetion of VBComponent.ReadProperty but have not gotten
> it to work.
>
> I really need to find out how this works as I dont really know enough
> about Addins at the moment and only have one small book as a refernce.

To get the Name of the object associated with a CodePane, try looping
through VBComponents collection to find CodePane.CodeModule =
VBComponent.CodeModule, then use VBComponent.Name.

Also, try searching this site for Addins:

http://www.planet-source-code.com

There are 67 results for "addin", and 14 results for "addin resize".


Kevin Provance

unread,
May 5, 2009, 10:04:57 PM5/5/09
to
I think he wants the dimensions for the currently selected form, not the
code panel

--
2025
If you do not believe in time travel,
your beliefs are about to be tempered.

http://www.facebook.com/group.php?gid=43606237254


"Nobody" <nob...@nobody.com> wrote in message

news:%23XePHXe...@TK2MSFTNGP02.phx.gbl...

k_zeon

unread,
May 6, 2009, 4:14:01 AM5/6/09
to
Hi

I have managed to get the following code which gives me the form name but i
still cannot get the width and height
I get an error

Dim vbcom As VBComponent, test As String
Dim vbform As Object


For Each vbcom In VBInstance.ActiveVBProject.VBComponents

If vbcom.Name = VBInstance.ActiveCodePane.CodeModule Then

Set vbform = VBInstance.ActiveCodePane.CodeModule <<<<<< This is
causing the error.....

test = vbform.Height
Exit For
End If
Next

MsgBox test

Can someone help me find the solution

thanks

Garry

"Kevin Provance" <Bill.McCarthy.Is.Stalking.TPASoft.com...@nowhere.edu>
wrote in message news:uSh5O8ez...@TK2MSFTNGP06.phx.gbl...

Michael Williams

unread,
May 6, 2009, 4:37:51 AM5/6/09
to
"k_zeon" <silverm...@googlemail.com> wrote in message
news:OHYgeKiz...@TK2MSFTNGP02.phx.gbl...

> I have managed to get the following code which gives me
> the form name but i still cannot get the width and height

> I get an error . . .

I must admit that I don't really understand what you are doing because I've
never written an IDE Add-In myself, but it looks as though you are writing
an Add-In to create and insert code into a Form in order to perform some
kind of automatic resizing at run time? If that is the case, might it not be
a bit easier to write it as a User Control that can be dropped onto a Form?

Mike

Michael Williams

unread,
May 6, 2009, 5:22:08 AM5/6/09
to

. . . actually, on reflection, my previous suggestion of using a User
Control will probably not work. I thought that you could pick up the design
time ScaleWidth and ScaleHeight in the Initialise event before the Form
loaded and altered those values in cases where the design time size will not
fit the runtime display, but that only works in certain specific
circumstances and does not work in general.

Mike

Nobody

unread,
May 6, 2009, 5:57:10 AM5/6/09
to
"k_zeon" <silverm...@googlemail.com> wrote in message
news:OHYgeKiz...@TK2MSFTNGP02.phx.gbl...

> If vbcom.Name = VBInstance.ActiveCodePane.CodeModule Then

The left side is a String, the right side is an Object. Not the same type. I
don't know what's the default property for CodeModule is, but it's better to
specify default properties. In any case, the line I quoted is not what I
meant. Try:

If Not vbcom.CodeModule Is Nothing Then
If vbcom.CodeModule Is VBInstance.ActiveCodePane.CodeModule Then
Debug.Print vbcom.Name
...

Or you can download one of the Addin samples and save some time.


k_zeon

unread,
May 6, 2009, 6:01:54 AM5/6/09
to
Hi Mike

I already have a module with code to save form sizes and reload them when
the form is open again.

At present I manually insert in Form Load ' LoadSetting
Me,Width,Height,XCord,YCord)

I have to get the width and height manually from the Properties window and
put the code in.
then I have to goto the Query_Unload_Form and enter ' Unloadsettings me '

I would much rather click my addin to get the current form sizes and then
automatically insert the text

If the Events are in the code window, just add the insert text.
If The events ie Load and Unload are not even there then my addin with
create them and insert the text

Please I need someone to help me get the Size of the currently selected form
through my addin.

I hope someone can help

thanks

Garry

"Michael Williams" <Mi...@WhiskeyAndCoke.com> wrote in message
news:OnEZcwiz...@TK2MSFTNGP03.phx.gbl...

k_zeon

unread,
May 6, 2009, 6:09:25 AM5/6/09
to
Hi

I am emailing you direct in hopes of solving my problem.
I have downloaded Addin codes from Planetsourcecode and this is the reason I
have the code so far.

I can get the form name etc from the code below.

Dim vbcom As VBComponent, test As String
Dim vbform As Object


For Each vbcom In VBInstance.ActiveVBProject.VBComponents

If vbcom.Name = VBInstance.ActiveCodePane.CodeModule Then ' This is
FORM1

Set vbform = VBInstance.ActiveCodePane.CodeModule <<<<<< This is
causing the error.....

'How do i set Form1 so that i can then say vbform.height and get the
height of the currently selected form

test = vbform.Height
Exit For
End If
Next

MsgBox test


What I cannot do is access the properties of the vbcom.Name ie vbcom.Name
would be Form1

I then need to get the width and height of Form1 but at present cannot get
it to work.

I have tried many different combinations to get the properties and the only
height i CAN get is the design window height which is always 636

thanks

Garry

"Nobody" <nob...@nobody.com> wrote in message

news:#AMjNEjz...@TK2MSFTNGP04.phx.gbl...

k_zeon

unread,
May 6, 2009, 6:52:26 AM5/6/09
to
Hi

I managed to solve my problem

Dim vbcom As VBComponent, vbfHeight As String, vbfWidth As String

For Each vbcom In VBInstance.ActiveVBProject.VBComponents

If vbcom.Name = VBInstance.ActiveCodePane.CodeModule Then

vbfHeight = vbcom.Properties("height")
vbfWidth = vbcom.Properties("width")


Exit For
End If
Next

Set vbcom = Nothing

just in case anyone is interested.

thanks

Garry

"k_zeon" <silverm...@googlemail.com> wrote in message

news:e5pfBLjz...@TK2MSFTNGP04.phx.gbl...

0 new messages