|
-
June 17th, 2001, 11:47 AM
#1
new creates 2....
I have the following code in a command button:
private Sub Command1_Click()
Dim n as Form1
set n = new Form1
n.show
End sub
But when i click on the button it creates 2 new forms the first time.
how can i solve this?
--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: [email protected]
for the address
-
June 17th, 2001, 12:51 PM
#2
Re: new creates 2....
Hmm, I got this problem myself, and it was because somewhere I reffered to the form directly, not to the instance of the form. This makes that another instance of the form was created.
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
-
June 17th, 2001, 02:45 PM
#3
Re: new creates 2....
How am i doing that?
--Ant
--------------------------------------------------
check out my newest freeware
E-mail me at: [email protected]
for the address
-
June 17th, 2001, 02:58 PM
#4
Re: new creates 2....
Your sample creates only one additional form on my computer. Running your sample should result in having two forms afterwards, The original and the newly created copy.
John G
-
June 18th, 2001, 04:56 AM
#5
Re: new creates 2....
Or you have the commandbutton in form1, and so you have two as 1 is the first where command clicked is and second is the new one, or you called click twice
(maybe once with clicking, and a second via code setting command1= true)
try adding a secod form, and modifying your click code this way:
Dim n as Form2
set n = new Form2
n.Show
how many Form2 do you have now?
Of course, using New keyword you will have a new form each time. If you want only one no matter how many time you click on command button, do the following:
Dim n as Form1
set n = Form1
n.Show
You have to provide a way to set n to nothing. Here may be a way to do it:
option Explicit
'General declaration
Dim n as Form2
private Sub Command1_Click()
'only if it is not already set. However, it will not cause an error
'if not tested
If n is nothing then
set n = Form2
End If
n.Show
End Sub
private Sub Form_Unload(Cancel as Integer)
Dim f as Form
for Each f In Forms
If f.Name <> me.Name then
Unload f
set f = nothing
End If
next
If Not n is nothing then
'set the n form_variable to nothing
'to free memory
set n = nothing
End If
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
June 18th, 2001, 04:59 AM
#6
Re: I will become a Joker here...
Sorry. Did not see all answers...
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
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
|