|
-
Jun 5th, 2000, 04:05 PM
#1
Thread Starter
Lively Member
I know how to create one. But deleting is harder. Can't find example code on it anywhere. Topic is little known probably.
Dim MyCmd As Control
Set MyCmd = Controls.Add("Forms.CommandButton.1")
MyCmd.left = 18
MyCmd.top = 50
MyCmd.width = 175
MyCmd.height = 20
MyCmd.Caption = "This iz fun. " & MyCmd.Name
I've tried
MyCmd.Delete
but only get an error 91.
Anyone know the answer?
-
Jun 5th, 2000, 04:23 PM
#2
transcendental analytic
I hope i'm not talking bullcrap since i don't have vb6 and i can't create my controls in vb5 but you could try this:
Set MyCmd = Nothing
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 5th, 2000, 04:28 PM
#3
Fanatic Member
I do belive that it is
Only works for controls created at runtime.
Iain, thats with an i by the way!
-
Jun 5th, 2000, 04:44 PM
#4
Thread Starter
Lively Member
Still doesnt work. This is VBA in Office97. VB5 more or less.
The controll is created at runtime as described:
Dim MyCmd As Control
Private Sub UserForm_Click()
Set MyCmd = Controls.Add("Forms.CommandButton.1")
MyCmd.left = Rnd * 50
MyCmd.top = Rnd * 50
MyCmd.width = 20
MyCmd.height = 20
MyCmd.Caption = "Fun" & MyCmd.Name
End Sub
Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 27 Then Unload MyCmd 'ESCAPE pressed
End Sub
When pressing Escape i get "Cannot load or remove object" runtime error 361.
-
Jun 5th, 2000, 04:59 PM
#5
Fanatic Member
Sorry that is for unloading control array elements.
Give this one a whirl 
Code:
Me.Controls.Remove ("myCmd")
Iain, thats with an i by the way!
-
Jun 5th, 2000, 05:13 PM
#6
PowerPoster
Originally posted by Thomas Halsvik
know how to create one. But deleting is harder. Can't find example code on it anywhere. Topic is little known probably.
Dim MyCmd As Control
Set MyCmd = Controls.Add("Forms.CommandButton.1", "<Control Name>")
MyCmd.left = 18
MyCmd.top = 50
MyCmd.width = 175
MyCmd.height = 20
MyCmd.Caption = "This iz fun. " & MyCmd.Name
I've tried
MyCmd.Delete
but only get an error 91.
Anyone know the answer?
I think you need to assign a name to the newly created CommandButton, else you can not remove the control with the Romove method.
Code:
Controls.Remove "<Control Name>"
-
Jun 5th, 2000, 05:23 PM
#7
Thread Starter
Lively Member
Thanks. That last one worked. Strange how little there is to be found on the net about this subject.
Well. I'm happy. Now I have a new degree of freedom.
----------------------------------------------------
Question: How do u get lines in the posts?
-
Jun 5th, 2000, 05:30 PM
#8
PowerPoster
Just the UUB Code
just read this & you'll know how we did it.
http://forums.vb-world.net/index.php?action=bbcode
[Edited by Chris on 06-06-2000 at 02:34 PM]
-
Jun 6th, 2000, 12:46 AM
#9
Member
I pasted the code...It works fine...But I am not able to figure out how to use that Command Button.If I want to handle the Click Event, how do I do that....
thanks
Neelesh
-
Jun 6th, 2000, 12:47 AM
#10
Fanatic Member
you have to dim myCmd as a command button and use the WithEvents Keyword.
Now you can program all of the events.
Code:
Dim WithEvents myCmd as CommandButton
Iain, thats with an i by the way!
-
Jun 6th, 2000, 12:54 AM
#11
PowerPoster
Then you may need to change this one as well
Code:
Set MyCmd = Controls.Add("Forms.CommandButton.1")
To
Set MyCmd = Controls.Add("vb.CommandButton",<Control Name>)
[Edited by Chris on 06-06-2000 at 09:56 PM]
-
Jun 6th, 2000, 01:12 AM
#12
Member
Still I am confused...
Could you please write code for just one event (with all the variables correctly defined)
thanks
neel
-
Jun 6th, 2000, 03:26 PM
#13
Fanatic Member
Here we go then.
Declaring and Setting + Code for the click event.
[code]
'General Declaractions
Dim WithEvents myCmd As CommandButton
Private Sub Form_Load()
Set MyCmd = Controls.Add("Forms.CommandButton.1","myCmd")
End Sub
Private Sub myCmd_Click()
msgbox "Hello World"
End Sub
Iain, thats with an i by the way!
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
|