|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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. :) 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 = True '// Form2 Option Explicit bSomething = False '// Form3 Option Explicit MsgBox bSomething Show quoteHide quote "Vincent" <vincent***@hotmail.com> wrote in message news:#QmnHWVZFHA.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. > > Thanks for any help. :) > > >
Show quote
Hide quote
"Vincent" <vincent***@hotmail.com> wrote in message Not sure exactly what code you want to reproduce, but if it is variables, 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. 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 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\
Show quoteHide quote "YYZ" <n***@none.com> wrote in message news:#HUvboVZFHA.1152@tk2msftngp13.phx.gbl... > "Vincent" <vincent***@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 > > "Steven Burn" <somewhere@in-time.invalid> wrote in message Both of the methods suggested will work..... though personally, I tend to go news:%23BX6csVZFHA.2756@tk2msftngp13.phx.gbl... 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 "Steven Burn" <somewhere@in-time.invalid> wrote in message Both of the methods suggested will work..... though personally, I tend to go news:%23BX6csVZFHA.2756@tk2msftngp13.phx.gbl... with modules over classes as I find them easier to work with for some reason :o\ I'm the opposite. To me, classes are easier. For one thing, there's no need to worry about variable, procedure or API declarations stomping on each other if they're private to the class (I guess you can do that with modules too but...) Regardless, I tend to put stuff in class modules. I like the ability to instantiate them only when needed. -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Sign up now to help keep VB support alive - http://classicvb.org/petition Please keep all discussions in the groups.. Thats my main problem lol........ I tend to forget to instantiate them..... with modules I don't have to worry about it <vbg>
Show quoteHide quote "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message news:u4bf9HfZFHA.3840@tk2msftngp13.phx.gbl... > "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\ > > I'm the opposite. To me, classes are easier. For one thing, there's no need > to worry about variable, procedure or API declarations stomping on each > other if they're private to the class (I guess you can do that with modules > too but...) Regardless, I tend to put stuff in class modules. I like the > ability to instantiate them only when needed. > > > -- > Ken Halter - MS-MVP-VB - http://www.vbsight.com > DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm > Sign up now to help keep VB support alive - http://classicvb.org/petition > Please keep all discussions in the groups.. > > Plus why load code into memory that may only be used once during an
applications lifetime or for a very short time. -- Show quoteHide quoteChris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp -- Read. Decide. Sign the petition to Microsoft. http://classicvb.org/petition/ "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message news:u4bf9HfZFHA.3840@tk2msftngp13.phx.gbl... > "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\ > > I'm the opposite. To me, classes are easier. For one thing, there's no need > to worry about variable, procedure or API declarations stomping on each > other if they're private to the class (I guess you can do that with modules > too but...) Regardless, I tend to put stuff in class modules. I like the > ability to instantiate them only when needed. > > > -- > Ken Halter - MS-MVP-VB - http://www.vbsight.com > DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm > Sign up now to help keep VB support alive - http://classicvb.org/petition > Please keep all discussions in the groups.. > > 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. :) "Vincent" <vincent***@hotmail.com> wrote in message Okay, at first glance, all those API calls and constants and types should go news:OdqRbZYZFHA.796@TK2MSFTNGP10.phx.gbl... > Hey Steve and Matt, > > Thanks for the input. Here is the code that goes into the General > Declarations: 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 Me again. :)
Here's the project I am working with: http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=8445&lngWId=1 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. :) 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 Vincent wrote:
> Thanks for the help, Matt. :) For each of the methods in form that are prefixed ISubclass_, just open each> > 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 of them in turn so that the property and end property exist. They just simply need to be created. -- Regards, Michael Cole
Show quote
Hide quote
"Michael Cole" <no***@hansen.com> wrote in message In case you didn't understand Michael's instructions, in VB, in the dropdown news:et01n%23ZZFHA.2756@tk2msftngp13.phx.gbl... > 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. on the left side at the top of the code window, choose "ISubclass" -- then in the combo on the right, click on each -- you have have 3 procedures created. You DO need to code some things in there, I believe -- here's what I have, at a minimum for the form that implements ISubclass Private Property Let ISubclass_MsgResponse(ByVal RHS As SSubTimer6.EMsgResponse) ' End Property Private Property Get ISubclass_MsgResponse() As SSubTimer6.EMsgResponse ISubclass_MsgResponse = emrConsume End Property Private Function ISubclass_WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long ' End Function Now, if you are going to subclass then you will do most of your work in the _WindowProc function. But I bet your original form has these 3 methods, and you'll probably want to copy them from there. Matt
VBclassic petition
Draw line on picture; change width Class_Terminate problem & Run-time error'424': Object required determining a rising\falling trend Creating a Toolbar Search box at bottom of screen Working application - Now generates error loop Duplicate forms help with passing values from an aspx page? |
|||||||||||||||||||||||