Re: Two Controls, One Event
Code:
Dim WithEvents button1 As VB.CommandButton
Dim WithEvents button2 As VB.CommandButton
Set button1 = Controls.Add("VB.CommandButton", "btn1", Form2)
Set button2 = Controls.Add("VB.CommandButton", "btn2", Form2)
Re: Two Controls, One Event
Suddenly hungry for chocolate ice cream.
Re: Two Controls, One Event
uuh, The amount of buttons gonna be created isnt fix since user sets it
Re: Two Controls, One Event
how I managed to get 2 replys and 131 views
Re: Two Controls, One Event
A WithEvents variable is no different from any other VB variable - if you assign to it twice the old value is erased! Why would you expect it to trigger an event from a button that it isn't pointing to?
If you define your button control as a control array by setting the Index property, then you can add or remove your buttons as needed dynamically, and they will all share the same event handlers. This is probably what you want.
Otherwise if you want a single event handler routine for multiple buttons that aren't in a control array, you'd need a collection of classes that each have their own WithEvents variable.
Re: Two Controls, One Event
Quote:
Originally Posted by
gaouser
how I managed to get 2 replys and 131 views
Most of the 'views' are bots crawling the forum. It means nothing. Some of the others are people who looked at the question and then got called away by an urgent phone call.
Re: Two Controls, One Event
"ugrent phone call" is a bit sus?
Re: Two Controls, One Event
You have a firm grasp of the obvious.
Re: Two Controls, One Event
Quote:
Originally Posted by
gaouser
Quote:
Originally Posted by
Shaggy Hiker
Most of the 'views' are bots crawling the forum. It means nothing. Some of the others are people who looked at the question and then got called away by an urgent phone call.
"ugrent phone call" is a bit sus?
Not gonna ask Shaggy how he knows this?
The man is GOD!