Yukidaruma759 Member Aug 18, 2017 #1 Is it possible to loop click events? For example, if you declare the buttons like this in Sub Global. How would call the click_events for each button? Code: Private btn(3) as Button
Is it possible to loop click events? For example, if you declare the buttons like this in Sub Global. How would call the click_events for each button? Code: Private btn(3) as Button
KMatle Expert Licensed User Longtime User Aug 19, 2017 #2 You mean 3 buttons and just one click event sub? 1. Give every button the SAME event name (example: "MyButton" in Initialize) 2. Give every button a different tag (example 1 to 10 in a loop) 3. In the click event sub (example: MyButton_Click) Code: Sub MyButton_Click Dim b As Button b=Sender 'the sending button :-) Select b.Tag 'if you have set the tag to 1 and 2. Change if you have set it to another value... Case "1" 'code for button 1 Case "2" 'code for button 2 End Select End Sub This works for "all" views! Hint: If you create views by code then store them in e.g. a list to retrieve them later (= Button number 5). Otherwise you have to get it from the parent view which is possible, too but not recommended. Upvote 0
You mean 3 buttons and just one click event sub? 1. Give every button the SAME event name (example: "MyButton" in Initialize) 2. Give every button a different tag (example 1 to 10 in a loop) 3. In the click event sub (example: MyButton_Click) Code: Sub MyButton_Click Dim b As Button b=Sender 'the sending button :-) Select b.Tag 'if you have set the tag to 1 and 2. Change if you have set it to another value... Case "1" 'code for button 1 Case "2" 'code for button 2 End Select End Sub This works for "all" views! Hint: If you create views by code then store them in e.g. a list to retrieve them later (= Button number 5). Otherwise you have to get it from the parent view which is possible, too but not recommended.