|
-
Mar 14th, 2005, 06:16 PM
#1
Thread Starter
Member
duplicating forms at runtime RESOLVED
How do you duplicate a form at run time? I got a form called frmComputerCards. I wanting to duplicate the form and have it work the same way that frmcomputercards works. Is that possible?
Last edited by simgirl; Mar 20th, 2005 at 05:26 PM.
Reason: Resolved
-
Mar 14th, 2005, 06:26 PM
#2
Frenzied Member
Re: duplicating forms at runtime
Something like this:
VB Code:
Sub FireUpForms(ByVal iNumForms As Integer)
Dim oForm As frmComputerCards
Dim i As Integer
For i = 0 To iNumForms - 1
Set oForm = New frmComputerCards
oForm.Show
Set oForm = Nothing
Next i
End Sub
-
Mar 14th, 2005, 06:29 PM
#3
Re: duplicating forms at runtime
 Originally Posted by simgirl
How do you duplicate a form at run time? I got a form called frmComputerCards. I wanting to duplicate the form and have it work the same way that frmcomputercards works. Is that possible?
or something like this:
Code:
Dim FormObj as Form
Set FormObj = Forms.Add("frmComputerCards")
Load FormObj
-
Mar 14th, 2005, 07:13 PM
#4
Re: duplicating forms at runtime
 Originally Posted by szlamany
or something like this:
Code:
Dim FormObj as Form
Set FormObj = Forms.Add("frmComputerCards")
Load FormObj
Does that actually create an instance of frmComputerCards?
I use:
Code:
Private Sub ShowNewForm()
Dim frmNew As frmMyForm
Set frmNew = New frmMyForm
Load frmNew
frmNew.Show
Set frmNew = Nothing
End Sub
This can be extended to show items from a DB.
Etc.
Code:
Private Sub ShowUser(ByVal plngUserID As Long)
Dim frmNew As frmUser
'code to load user data/object (this can also be in the form load if you want)
Set frmNew = New frmMyForm
'pass data/object to form
Load frmNew
frmNew.Show
Set frmNew = Nothing
End Sub
Woka
-
Mar 14th, 2005, 07:22 PM
#5
Re: duplicating forms at runtime
 Originally Posted by Wokawidget
Does that actually create an instance of frmComputerCards?
I use:
Code:
Private Sub ShowNewForm()
Dim frmNew As frmMyForm
Set frmNew = New frmMyForm
Load frmNew
frmNew.Show
Set frmNew = Nothing
End Sub
This can be extended to show items from a DB.
Etc.
Code:
Private Sub ShowUser(ByVal plngUserID As Long)
Dim frmNew As frmUser
'code to load user data/object (this can also be in the form load if you want)
Set frmNew = New frmMyForm
'pass data/object to form
Load frmNew
frmNew.Show
Set frmNew = Nothing
End Sub
Woka
Yes it does - and the reason we use it is because the FORM name can be in a variable. That's helpful in a MDI-type app.
You would have to have a different line of code for every FORM you could possibly add.
-
Mar 14th, 2005, 07:29 PM
#6
Re: duplicating forms at runtime
I didn't know that.
Very handy to know
Woka
-
Mar 18th, 2005, 12:54 PM
#7
Thread Starter
Member
Re: duplicating forms at runtime
I am able now to duplicate a form but not changing anything on the duplicated form at run time. I can't change the text in labels or anything. How can I fix that problem?
frmMenu
Set frmComputerCards1 = New frmComputerCards
frmComputerCards1.Caption = "Computer Player 1"
frmComputerCards1.Show
I'm trying to make changes to that new form from the main players game screen form. Why am I getting this problem?
-
Mar 18th, 2005, 01:17 PM
#8
Re: duplicating forms at runtime
Code:
Set frmComputerCards1 = New frmComputerCards
Load frmComputerCards1
frmComputerCards1.Caption = "Computer Player 1"
frmComputerCards1.txtUsername.Text = "Woka"
frmComputerCards1.Show
Woka
-
Mar 18th, 2005, 01:25 PM
#9
Re: duplicating forms at runtime
Keep in mind that "frmComputerCards1" is a form object local to whatever sub/func you are creating the new instance of the form in.
It will not be the name of the form throughout the program - right?
We always use the FORMS() collection to access the forms we "duplicate"...
-
Mar 18th, 2005, 01:30 PM
#10
Re: duplicating forms at runtime
I would write this as:
Code:
Dim frmNew As frmComputerCards
Set frmNew = New frmComputerCards
Load frmNew
With frmNew
.Caption = "Woof"
.txtUsername.Text = "Woka"
.Show
End With
Set frmNew = Nothing
szlamany, yup, you are right. frmNew will only be a local object name in the confines of the funtion you have: Dim frmNew As, in.
Woof
-
Mar 18th, 2005, 11:22 PM
#11
Thread Starter
Member
Re: duplicating forms at runtime
Thanks that helped a lot. I got 1 last question related to this topic. If I want the user to be able to choose between 1 to 8 computer players. Whats the easiest way to load the forms?
-
Mar 19th, 2005, 06:42 AM
#12
Re: duplicating forms at runtime
Use either method - FORMS.ADD("formname") or the .SHOW/LOAD method with a FORM object.
But then in some GLOBAL array you could store the (FORMS.COUNT-1) value of the newly added form.
You can refer to the form by FORMS(x).whatever with x being the value of the newly added form.
-
Mar 20th, 2005, 05:25 PM
#13
Thread Starter
Member
Re: duplicating forms at runtime
Thanks everybody for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|