Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 3rd, 2006, 10:19 PM
Authorized User
 
Join Date: Jul 2003
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default Is there a way to call forms dynamically

'Proper way
'dim f as form1
'set f = new form1
'f.show
'or
'form1.show
------------------------------
is there a way around in doing it like this

Dim f as form
set f = rs(0).value & ""
redim f as new form 'now has the value
form.show 'generic way of showing forms
------------------------------
need your comments, suggestions and violent reactions

Proud To Be Pinoy
__________________
Proud To Be Pinoy
 
Old July 5th, 2006, 12:51 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Variable names are only something to help us humans.
On compilation, they are converted to tokens (IDs generated by the compiler), and those tokens are utilized in generating the .EXE. So, at the time the recordset is being actually read by the machine to extract its value, there is no ‘thing’ named “form1.”

There is a Forms collection of all loaded forms, but the object you are after does not yet exist so as to be found in the Forms collection, then so as to use that reference to create the instance to add to the collection...

In the bigger picture, what are you trying to do?
 
Old July 5th, 2006, 07:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sure you can do it, just use Forms.Add using the name of the form (that I guess is stored in a database:

dim f as form
set f = forms.add(rs(0).value)
f.Show
 
Old July 6th, 2006, 11:46 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

How did you find this?

I can find nothing on it in help, the object browser does not list the .Add method of Forms, and IntelliSense provides no argument/format assistance!

Once I insert the statement the IDE corrects the case of what I typed, and it does work syntax functions...

Kudos!
 
Old July 6th, 2006, 12:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Forms is defined as Object, so the intelliSense cannot display its methods.
As for the missing documentation, well it is not the first time isn't it :)
 
Old July 6th, 2006, 12:57 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

???
marcostraf:
What good is adding a form to the forms collection based on its string name? What exactly is this accomplishing for you? Now that it is in the forms collection, what is it that you propose you are going to do with it?


Woody Z http://www.learntoprogramnow.com
 
Old July 6th, 2006, 04:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ask reyboy, the original poster :)

let's say you have a project with one main form and a bunch of other forms that need to be displayed or by user action, or by reading some information from some place. For example, like in the case of the original poster, the user reads a data from a database table, and one field of the table tells back which form needs to be open to process that data.
 
Old July 7th, 2006, 10:13 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:... the user reads a data from a database table, and one field of the table tells back which form needs to be open to process that data.
Yes, but your example won't open a form. It will merely add the form to the forms collection... which has no practical effect.

There are several ways to dynamically open a form based on some data from the database, but adding it to the forms collection isn't one of them.

And of course, there are numerous reasons I could think of for wanting to dynamically open forms. It isn't clear to me from the original question what the exact need is, or why this is something that he is trying to do.

Here is a bit more complex scenario that makes sense to me:
An application is made up of numerous dlls, some of which contain GUI elements, and is configured using database tables to dictate things such as what menu options to display, what actions are taken when those menu options are selected, and what dlls provide what services. The dlls would be loaded dynamically (and probably be late bound in this scenario, or implement known and referenced interfaces). I would suggest that perhaps the design would depend on a factory method of some type to dish out the appropriate forms and functionality for any particular use.

Woody Z http://www.learntoprogramnow.com
 
Old July 7th, 2006, 12:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:[i]...Yes, but your example won't open a form....
what are you talking about? in my code I first load the form using Forms.Add (remember that Forms is the object that keeps the collection of loaded forms) and then I show it using f.Show
It works great (from many years, I'll say that it is in my projects at least since 1998)
 
Old July 7th, 2006, 05:34 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes. But this won't open an existing form2 if one exists. It is actually creating a NEW form2 in adding it to the collection. If you were to run it 3 times without closing the form each time you would end up with 3 forms in your form collection. You are not opening the form, you are creating a new one and showing it. Perhaps it works great for you, but overall, this is a questionable practice at best.

What you might want to do is first loop through the forms collection checking if the form you want to open already exists in the collection.

Woody Z http://www.learntoprogramnow.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically load new forms into Frames MichaelS Classic ASP Professional 0 July 11th, 2006 02:59 PM
Dynamically call javascript functions austinf Javascript 1 May 13th, 2006 07:31 AM
Loading forms dynamically bmains C# 2005 1 November 30th, 2005 03:53 PM
Save Dynamically created forms DaDeViL Access VBA 2 August 17th, 2005 08:29 AM
Dynamically resizing forms siptah Access 4 May 11th, 2005 04:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.