Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Using "Include" Approach for Repetitive Code...
Hello Friends,

I am mainly a ASP web developer so I have been looking into the possibilty
of using an "include" style approach to adding code to my VB6 forms.  In ASP
you can place <!--#include file="mypath/mypage.asp" -->  at the top of any
document to prevent having to retype the same code in every document.  Is
there something like this for VB6...?  I have an app that uses several forms
and they all need the same large chunk of code in the General Declarations.

I am familar with making public subs, functions and other global data but I
have not found a solution to my problem using these approaches.

Thanks for any help. :)




Report this thread to moderator Post Follow-up to this message
Old Post
Vincent
05-31-05 01:55 AM


Re: Using "Include" Approach for Repetitive Code...
Project > Add Module

Stick all of the code you need to duplicate in there :o)

e.g.

'// Module1
Option Explicit

Public bSomething As Boolean

'// Form1
Option Explicit
bSomething =3D True

'// Form2
Option Explicit
bSomething =3D False

'// Form3
Option Explicit
MsgBox bSomething

--=20
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Vincent" <vincent938@hotmail.com> wrote in message =
news:#QmnHWVZFHA.1868@TK2MSFTNGP14.phx.gbl...
> Hello Friends,
>=20
> I am mainly a ASP web developer so I have been looking into the =
possibilty=20
> of using an "include" style approach to adding code to my VB6 forms.  =
In ASP=20
> you can place <!--#include file=3D"mypath/mypage.asp" -->  at the top =
of any=20
> document to prevent having to retype the same code in every document.  =
Is=20
> there something like this for VB6...?  I have an app that uses several =
forms=20
> and they all need the same large chunk of code in the General =
Declarations.
>=20
> I am familar with making public subs, functions and other global data =
but I=20
> have not found a solution to my problem using these approaches.
>=20
> Thanks for any help. :)
>=20
>=20
>=20


Report this thread to moderator Post Follow-up to this message
Old Post
Steven Burn
05-31-05 01:55 AM


Re: Using "Include" Approach for Repetitive Code...
"Vincent" <vincent938@hotmail.com> wrote in message
news:%23QmnHWVZFHA.1868@TK2MSFTNGP14.phx.gbl...
> Hello Friends,
>
> I am mainly a ASP web developer so I have been looking into the possibilty
> of using an "include" style approach to adding code to my VB6 forms.  In
> ASP you can place <!--#include file="mypath/mypage.asp" -->  at the top of
> any document to prevent having to retype the same code in every document.
> Is there something like this for VB6...?  I have an app that uses several
> forms and they all need the same large chunk of code in the General
> Declarations.
>
> I am familar with making public subs, functions and other global data but
> I have not found a solution to my problem using these approaches.

Not sure exactly what code you want to reproduce, but if it is variables,
then create a class, and create an instance for each form -- then all your
variables will be specific to that form.

If you have code to use, then, as Steven suggested, put it into a module.
You may have to pass the form to use as a parameter to all those functions.
I do this a lot.

But without more explanation, I dont know which solution, if either, will
work for you.

Matt



Report this thread to moderator Post Follow-up to this message
Old Post
YYZ
05-31-05 01:55 AM


Re: Using "Include" Approach for Repetitive Code...
Both of the methods suggested will work..... though personally, I tend =
to go with modules over classes as I find them easier to work with for =
some reason :o\

--=20
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"YYZ" <none@none.com> wrote in message =
news:#HUvboVZFHA.1152@tk2msftngp13.phx.gbl...
> "Vincent" <vincent938@hotmail.com> wrote in message=20
> news:%23QmnHWVZFHA.1868@TK2MSFTNGP14.phx.gbl... 
possibilty=20 
In=20 
the top of=20 
document.=20 
several=20 
data but=20 
>=20
> Not sure exactly what code you want to reproduce, but if it is =
variables,=20
> then create a class, and create an instance for each form -- then all =
your=20
> variables will be specific to that form.
>=20
> If you have code to use, then, as Steven suggested, put it into a =
module.=20
> You may have to pass the form to use as a parameter to all those =
functions.=20
> I do this a lot.
>=20
> But without more explanation, I dont know which solution, if either, =
will=20
> work for you.
>=20
> Matt=20
>=20
>=20


Report this thread to moderator Post Follow-up to this message
Old Post
Steven Burn
05-31-05 01:55 AM


Re: Using "Include" Approach for Repetitive Code...
"Steven Burn" <somewhere@in-time.invalid> wrote in message
news:%23BX6csVZFHA.2756@tk2msftngp13.phx.gbl...
Both of the methods suggested will work..... though personally, I tend to go
with modules over classes as I find them easier to work with for some reason
:o\

Oh, absolutely!  However, the last part of Vincent's message mentioned that
he was familiar with making public subs, functions, gllobals, etc, and that
thye wouldn't work for him.  That's the only reason I suggested the class
approach.  :)

Matt



Report this thread to moderator Post Follow-up to this message
Old Post
YYZ
05-31-05 08:57 AM


Re: Using "Include" Approach for Repetitive Code...
Hey Steve and Matt,

Thanks for the input.  Here is the code that goes into the General
Declarations:

Option Explicit

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As
Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X
As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long)
As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const SWW_HPARENT = (-8)
Private Const WM_MOVE = &H3
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Private Const WM_SIZE = &H5
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib "user32" ()

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long,
lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long,
ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As
Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hWndLock As
Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal
nCmdShow As Long) As Long
Private Enum ShowCommands
SW_HIDE = 0
SW_SHOWNORMAL = 1
SW_NORMAL = 1
SW_SHOWMINIMIZED = 2
SW_SHOWMAXIMIZED = 3
SW_MAXIMIZE = 3
SW_SHOWNOACTIVATE = 4
SW_SHOW = 5
SW_MINIMIZE = 6
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_RESTORE = 9
SW_SHOWDEFAULT = 10
SW_MAX = 10
End Enum

Private Declare Function ExcludeClipRect Lib "gdi32" (ByVal hDC As Long, _
ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
ByVal Y2 As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As
Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long
Private Declare Function GetClipRgn Lib "gdi32" (ByVal hDC As Long, _
ByVal hRgn As Long) As Long
Private Declare Function OffsetClipRgn Lib "gdi32" (ByVal hDC As Long, _
ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function DrawFrameControl Lib "user32" (ByVal hDC As Long, _
lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
Private Declare Function DrawIconEx Lib "user32" (ByVal hDC As Long, ByVal
xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As
Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, hbrFlickerFreeDraw
As Long, ByVal diFlags As Long) As Long
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hDC
As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal
wFormat As Long) As Long
Private Const DT_BOTTOM = &H8
Private Const DT_CENTER = &H1
Private Const DT_LEFT = &H0
Private Const DT_VCENTER = &H4
Private Const DT_TOP = &H0
Private Const DT_SINGLELINE = &H20
Private Const DT_RIGHT = &H2
Private Const DT_WORDBREAK = &H10
Private Const DT_CALCRECT = &H400
Private Const DT_WORD_ELLIPSIS = &H40000

Private Type DRAWITEMSTRUCT
CtlType As Long
CtlID As Long
itemID As Long
itemAction As Long
itemState As Long
hwndItem As Long
hDC As Long
rcItem As RECT
itemData As Long
End Type

Public Enum SysMet
SM_CXSCREEN = 0
SM_CYSCREEN = 1
SM_CXVSCROLL = 2
SM_CYHSCROLL = 3
SM_CYCAPTION = 4
SM_CXBORDER = 5
SM_CYBORDER = 6
SM_CXDLGFRAME = 7
SM_CYDLGFRAME = 8
SM_CYVTHUMB = 9
SM_CXHTHUMB = 10
SM_CXICON = 11
SM_CYICON = 12
SM_CXCURSOR = 13
SM_CYCURSOR = 14
SM_CYMENU = 15
SM_CXFULLSCREEN = 16
SM_CYFULLSCREEN = 17
SM_CYKANJIWINDOW = 18
SM_MOUSEPRESENT = 19
SM_CYVSCROLL = 20
SM_CXHSCROLL = 21
SM_DEBUG = 22
SM_SWAPBUTTON = 23
SM_RESERVED1 = 24
SM_RESERVED2 = 25
SM_RESERVED3 = 26
SM_RESERVED4 = 27
SM_CXMIN = 28
SM_CYMIN = 29
SM_CXSIZE = 30
SM_CYSIZE = 31
SM_CXFRAME = 32
SM_CYFRAME = 33
SM_CXMINTRACK = 34
SM_CYMINTRACK = 35
SM_CXDOUBLECLK = 36
SM_CYDOUBLECLK = 37
SM_CXICONSPACING = 38
SM_CYICONSPACING = 39
SM_MENUDROPALIGNMENT = 40
SM_PENWINDOWS = 41
SM_DBCSENABLED = 42
SM_CMOUSEBUTTONS = 43
SM_CMETRICS = 44
End Enum

Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As
Long) As Long

Private Const WM_GETSYSMENU = &H313
Private Const WM_NCPAINT = &H85
Private Const WM_DRAWITEM = &H2B
Private Const WM_ACTIVATE = &H6
Dim IsInFocus As Boolean
Dim xad As Long

Implements ISubclass
Private m_emr As EMsgResponse

Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As
Long
Private Const COLOR_ACTIVECAPTION = 2
Private Const COLOR_INACTIVECAPTION = 3
Private Const COLOR_INACTIVECAPTIONTEXT = 19
Dim colorActive As Long
Dim colorInActive As Long
Dim gColor1 As Long, gColor2 As Long
Dim gAngle As Long
Private mGradient As New clsGradient

The "Implements ISubclass" seems to not want to go into a bas file.

Thanks again for any help. :)





Report this thread to moderator Post Follow-up to this message
Old Post
Vincent
05-31-05 08:57 AM


Re: Using "Include" Approach for Repetitive Code...
Me again. :)

Here's the project I am working with:
[url]http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=8445&lngWId=1[/u
rl]

The main form has a truck load of code in it.  I am trying to not have to
add the code to each form in my project but have a centralized area.  I hope
this makes more sense.

Thanks again. :)



Report this thread to moderator Post Follow-up to this message
Old Post
Vincent
05-31-05 08:57 AM


Re: Using "Include" Approach for Repetitive Code...
"Vincent" <vincent938@hotmail.com> wrote in message
news:OdqRbZYZFHA.796@TK2MSFTNGP10.phx.gbl...
> Hey Steve and Matt,
>
> Thanks for the input.  Here is the code that goes into the General
> Declarations:

Okay, at first glance, all those API calls and constants and types should go
into a module as public -- I have a module in almost every project called
modAPI.bas, and it contains a bunch of this stuff.

As for the Implements ISubclass, I believe that that is the way of
subclassing from VBAccelerator.com -- if so, then I don;t think you can put
that into a module.  But, if you got rid of the rest, then adding in
Implements ISubclass wouldn't really be a problem, right?

Try that and come back if you have any problems.

Remember, change all the Privates to Publics.  That sounds dirty.

Matt



Report this thread to moderator Post Follow-up to this message
Old Post
YYZ
05-31-05 08:57 AM


Re: Using "Include" Approach for Repetitive Code...
Thanks for the help, Matt. :)

I have added all the code to a mod and changed the Private to Public
(Nothing dirty here) :)  .  I added the "Implements ISubclass" to the main
form in the general declarations but I receive an error:
Compile Error
Object module needs to implement 'MsgResponse' for interface 'ISubclass'.

Thanks.
V



Report this thread to moderator Post Follow-up to this message
Old Post
Vincent
05-31-05 08:57 AM


Re: Using "Include" Approach for Repetitive Code...
Vincent wrote:
> Thanks for the help, Matt. :)
>
> I have added all the code to a mod and changed the Private to Public
> (Nothing dirty here) :)  .  I added the "Implements ISubclass" to the
> main form in the general declarations but I receive an error:
> Compile Error
> Object module needs to implement 'MsgResponse' for interface
> 'ISubclass'.
>
> Thanks.
> V

For each of the methods in form that are prefixed ISubclass_, just open each
of them in turn so that the property and end property exist.  They just
simply need to be created.

--
Regards,

Michael Cole



Report this thread to moderator Post Follow-up to this message
Old Post
Michael Cole
05-31-05 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:37 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.