Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading Forms and Modules at runtime

Status
Not open for further replies.

vbprogramming

Programmer
Jun 3, 2003
7
0
0
US
Hi All!

I have forms and modules that are used by many different applications. All of my applications are written in VB. If I statically load all of the forms into each application then each time I modify the forms I have to re-compile each application. What I want is to just point to the forms in the application sub main routine and then load them at run time.

What I have now
sub main()
Startup.show 'load the startup form.
'the code in the startup form
'requires modules 1 -3 that
'are already loaded
end sub
What I need
sub main()
load the external Startup.frm file
load the 3 external modules
Startup.show
end sub
The difference between these is that the forms and modules would not actually be part of the exe file. The exe file would know where the forms and modules were located and would go get them and load them.
I have been looking around for the answer for several hours but have till now been unsuccessful.
Thanks!
 
I believe you may want to look into creating ActiveX Components.
 
I agree. In particular, set up an ActiveX DLL. Add whatever forms you like to it. In the class module, set up Methods (Public procs) to manipulate each form. When you instantiate the class from a client, to show that form, call the class method that does it.

Here's an example:
I have an ActiveX DLL project called FormList. It has 2 forms: frmThis & frmThat. It has a class called called MyFormList.

Inside the class are two procs:

Public Sub ShowForm(whichForm as Form)
whichForm.Show
End Sub

Public Sub HideForm(whichForm as Form)
whichForm.Hide
End Sub

Of course, you could make methods to unload, etc. as well.

Now, in my client, say a standard exe with a sub main, set a reference to FormList. Then add the following code:

Dim sknnnx as FormList
Set sknnnx = New FormList

sknnnx.ShowForm frmThis

et cetera...et cetera...

The point is that you encapsulate your forms' functionality in a class, then expose that functionality via methods of the class. A method is just a public Procedure. So long as you don't alter the method defnitions, you don't break the client by changing the forms.

HTH

Bob
 
I have been on Google for countless hours trying to resolve this. I am still not convinced that a activeX dll is the best way. I have a common exe file that is used in a dozen different modules. for each module they have their own forms that need to be used by the common startup program. The common startup program loads with a splash screen and a toolbar at the top for a config screen and a second toolbar for that modules files. If the use selects that modules files then the common exe file will need to go and grab the forms and modules for that program that the user selected. I am still stuck at the point where I have to precompile all of the forms into the exe file. I want to know a method that will allow me to load the forms at run time.

ie::
sub main()
load splash
end sub
sub module1_click()
dim dbs as database
set dbs = opendatabase("formsforModule1")
dim rst as dbs.recordset("select * from [forms]")
dim moduleform as form
set moduleform = app.path & rst.fields("moduleform")
rst.close
moduleform.show
end sub

The goal is that everytime I update a module form I don't have to recompile the existing exe file.

Bob Rodes had suggested using an ActiveX control and that might be the best way (although right now I have no idea how to do it)
One thing that I still question is
"I agree. In particular, set up an ActiveX DLL. Add whatever forms you like to it "
do I have to tie those forms to the ActiveX DLL file before I complie the exe file or can I do that at run time?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top