Discussion:
Re Inserting Code for addin
(too old to reply)
k_zeon
2009-05-03 22:22:55 UTC
Permalink
I would like to create an addin but am having some difficulties

in a newly created VB6 exe in the IDE you get

Option Explicit

Private Sub Form_Load()

End Sub


if i run my addin i get the correct results.
ie
Option Explicit

Private Sub Form_Load()
My Inserted Text <<<<< This is my inserted code
End Sub

if however i add some lines of code and white space as follows
ie

Option Explicit
Dim test as string
<<Space
<<Space
<<Space
Private Sub Form_Load()

End Sub

Now if I run my Addin I get


Option Explicit
Dim test as string
<<Space
My Inserted Text <<< This should be inside the Form_Load
<<Space
Private Sub Form_Load()

End Sub

He is the code i use to find the Form_Load Procedure

Private Function FindStartPlace(ByVal Stext As String) As Long
On Error Resume Next
Dim strProcNameExisits As Boolean
Dim lngProcStartLine As Long
Dim lngProcLineCount As Long
'
strProcNameExisits =
VBInstance.CodePanes.VBE.ActiveCodePane.CodeModule.Find(Stext, 1, 1,
VBInstance.ActiveCodePane.CodeModule.CountOfLines, 0, False, False)

If strProcNameExisits = False Then Exit Function

lngProcStartLine =
VBInstance.CodePanes.VBE.ActiveCodePane.CodeModule.ProcStartLine(Stext,
vbext_pk_Proc)



FindStartPlace = lngProcStartLine + 2
End Function


This will see the number of lines of code but does not take into account the
Blank Lines with Nothing there

I hope someone can help

Many thanks

Garry
Kevin Provance
2009-05-04 01:53:36 UTC
Permalink
You need to use the Find method, locate Sun Form_Load, which I believe
returns it's line number and use that return value to insert your text on
the correct line value. Messed up, I know...but that's what I did.
--
2025
If you do not believe in time travel,
your beliefs are about to be tempered.

http://www.facebook.com/group.php?gid=43606237254
"k_zeon" <***@googlemail.com> wrote in message news:***@TK2MSFTNGP03.phx.gbl...
|I would like to create an addin but am having some difficulties
|
| in a newly created VB6 exe in the IDE you get
|
| Option Explicit
|
| Private Sub Form_Load()
|
| End Sub
|
|
| if i run my addin i get the correct results.
| ie
| Option Explicit
|
| Private Sub Form_Load()
| My Inserted Text <<<<< This is my inserted code
| End Sub
|
| if however i add some lines of code and white space as follows
| ie
|
| Option Explicit
| Dim test as string
| <<Space
| <<Space
| <<Space
| Private Sub Form_Load()
|
| End Sub
|
| Now if I run my Addin I get
|
|
| Option Explicit
| Dim test as string
| <<Space
| My Inserted Text <<< This should be inside the
Form_Load
| <<Space
| Private Sub Form_Load()
|
| End Sub
|
| He is the code i use to find the Form_Load Procedure
|
| Private Function FindStartPlace(ByVal Stext As String) As Long
| On Error Resume Next
| Dim strProcNameExisits As Boolean
| Dim lngProcStartLine As Long
| Dim lngProcLineCount As Long
| '
| strProcNameExisits =
| VBInstance.CodePanes.VBE.ActiveCodePane.CodeModule.Find(Stext, 1, 1,
| VBInstance.ActiveCodePane.CodeModule.CountOfLines, 0, False, False)
|
| If strProcNameExisits = False Then Exit Function
|
| lngProcStartLine =
| VBInstance.CodePanes.VBE.ActiveCodePane.CodeModule.ProcStartLine(Stext,
| vbext_pk_Proc)
|
|
|
| FindStartPlace = lngProcStartLine + 2
| End Function
|
|
| This will see the number of lines of code but does not take into account
the
| Blank Lines with Nothing there
|
| I hope someone can help
|
| Many thanks
|
| Garry
|
|
Nobody
2009-05-04 02:20:02 UTC
Permalink
Post by k_zeon
I would like to create an addin but am having some difficulties
in a newly created VB6 exe in the IDE you get
Option Explicit
Private Sub Form_Load()
End Sub
if i run my addin i get the correct results.
ie
Option Explicit
Private Sub Form_Load()
My Inserted Text <<<<< This is my inserted code
End Sub
if however i add some lines of code and white space as follows
ie
Option Explicit
Dim test as string
<<Space
<<Space
<<Space
Private Sub Form_Load()
End Sub
Now if I run my Addin I get
Option Explicit
Dim test as string
<<Space
My Inserted Text <<< This should be inside the Form_Load
<<Space
Private Sub Form_Load()
End Sub
He is the code i use to find the Form_Load Procedure
Private Function FindStartPlace(ByVal Stext As String) As Long
On Error Resume Next
Dim strProcNameExisits As Boolean
Dim lngProcStartLine As Long
Dim lngProcLineCount As Long
'
strProcNameExisits =
VBInstance.CodePanes.VBE.ActiveCodePane.CodeModule.Find(Stext, 1, 1,
VBInstance.ActiveCodePane.CodeModule.CountOfLines, 0, False, False)
If strProcNameExisits = False Then Exit Function
lngProcStartLine =
VBInstance.CodePanes.VBE.ActiveCodePane.CodeModule.ProcStartLine(Stext,
vbext_pk_Proc)
FindStartPlace = lngProcStartLine + 2
End Function
This will see the number of lines of code but does not take into account
the Blank Lines with Nothing there
I hope someone can help
Many thanks
Garry
You need to use ProcBodyLine instead of ProcStartLine. ProcStartLine gives
you the first line of a procedure that would include any header. This is the
same line that appear after the separator in the IDE. ProcBodyLine gives you
the actual Sub/Function/Property declaration line.
k_zeon
2009-05-04 06:28:37 UTC
Permalink
thanks. I used ProcBodyLine and this solved my problem

many thanks
Post by Nobody
Post by k_zeon
I would like to create an addin but am having some difficulties
in a newly created VB6 exe in the IDE you get
Option Explicit
Private Sub Form_Load()
End Sub
if i run my addin i get the correct results.
ie
Option Explicit
Private Sub Form_Load()
My Inserted Text <<<<< This is my inserted code
End Sub
if however i add some lines of code and white space as follows
ie
Option Explicit
Dim test as string
<<Space
<<Space
<<Space
Private Sub Form_Load()
End Sub
Now if I run my Addin I get
Option Explicit
Dim test as string
<<Space
My Inserted Text <<< This should be inside the Form_Load
<<Space
Private Sub Form_Load()
End Sub
He is the code i use to find the Form_Load Procedure
Private Function FindStartPlace(ByVal Stext As String) As Long
On Error Resume Next
Dim strProcNameExisits As Boolean
Dim lngProcStartLine As Long
Dim lngProcLineCount As Long
'
strProcNameExisits =
VBInstance.CodePanes.VBE.ActiveCodePane.CodeModule.Find(Stext, 1, 1,
VBInstance.ActiveCodePane.CodeModule.CountOfLines, 0, False, False)
If strProcNameExisits = False Then Exit Function
lngProcStartLine =
VBInstance.CodePanes.VBE.ActiveCodePane.CodeModule.ProcStartLine(Stext,
vbext_pk_Proc)
FindStartPlace = lngProcStartLine + 2
End Function
This will see the number of lines of code but does not take into account
the Blank Lines with Nothing there
I hope someone can help
Many thanks
Garry
You need to use ProcBodyLine instead of ProcStartLine. ProcStartLine gives
you the first line of a procedure that would include any header. This is
the same line that appear after the separator in the IDE. ProcBodyLine
gives you the actual Sub/Function/Property declaration line.
Loading...