[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 578
  • Last Modified:

How do I add an Event Handler at run time in VB6

Greetings,

The question title says it all. I am adding Controls to a form dynamically (at run time) and I need a way to add an Event Handler to the Control as well.

I know that in VB.NET there is a AddHandler function but that function does not seem to exist for VB6 or at least I can't seem to locate it.

BTW, I am Not creating an array of Controls so the 'Events' are not available (exposed) through that mechanism.

Thanks for any help you can give

rrbecker
0
rrbecker
Asked:
rrbecker
  • 3
  • 3
1 Solution
 
jimbobmcgeeCommented:
What about

    Dim WithEvents newControl As New Text1

then using Text1's events?

J.

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Basically you can't.  VB6 uses control arrays to accomplish this.  The WithEvents keyword only allows you to handle ONE control.  It is possibly to create a dynamic control and assign it to a variable declared using WithEvents but you can only create ONE dynamic control in this way.  You must have a declaration for each "dynamic" control which makes it pretty silly and you might as use a control array since you must plan ahead at design time.
0
 
rrbeckerAuthor Commented:
Hi Idle_Mind

Ok, how about this. I have a structure that contains a Command Button (SSCommand).
I create an array of these structures and eventually add the Command Button to a Form.
How do I, (or can I) get at the 'Button_Click()' event for each command button in the structure?

-------example structure------------------
Type ItemDataStructure
    ItemIndex As Integer
    ItemNumber As Integer
    'ItemName As String
    ItemGroupName As String
    ItemButton As SSCommand <<-- Infragistics command button
    ButtonName As String
    ParentName As String
    ButtonWidth As Integer
    ButtonHeight As Integer
    ButtonTop As Integer
    ButtonLeft As Integer
    ButtonOrder As Integer
End Type
------------------------------------------------

Any Ideas?

BTW, I need to step out for a while, be back later today

rrbecker
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If the control supports it then you would need to create a control array of SSCommand.  When you create a new structure, also load another button into the control array.  Then instead of storing a button reference in your structure, you store the INDEX of the button in the control array.
0
 
rrbeckerAuthor Commented:
Hi Idle_Mind,

I'm back.... I've found that I can create and add the SSCommand button to a  form or panel by using the following syntax:

------------snippet--------------------
MainStruct.GroupStructure(GroupCounter).ItemStructure(ItemCounter).ItemButton.Container = MainStruct.GroupStructure(GroupCounter).GroupItemPanel
-------------------------------------

and this would display a new SSCommand button on my form. I can set all the other properties including Height, Width, Top and Left but I guess I still have the problem of being able to 'Read' the 'Click' event of the button.

If you have any other ideas I would appreciate it, otherwise I'll revert back to a 'Control' array and close this ticket.

Thanks in advance

rrbecker
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
As far as I know, you will have to use the control array method.

Sorry...
0
 
rrbeckerAuthor Commented:
Thanks Idle_Mind,

Not the answer I was 'Hoping' for but the 'Correct' answer none-the-less. You have helped me with problems in the past and have always given me the 'Best' solution possible.

So again, thanks for all your help, I will proceed to implement the 'Control Array'.

rrbecker
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now