Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 22nd, 2006, 07:28 PM
Authorized User
Join Date: Jan 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Button Handler Being called multiple times

Hello folks - here's another question for you:

I have a Class (class1), that inherits a Windows.Form. On a button click, it passes a reference of itself to another class (class2). The aim is to handle all of the form control events in class2, thus freeing up coding space in class1.

Class 2 looks like this:

Public Class Class2

   Dim cl1 As Class1
   Dim iCode As Integer

   Public SetData(ByVal iCode As Integer, ByRef cl1 As Class1)

      Me.iCode = iCode
      Me.cl1 = Class1

      'Add Button Handlers
      AddHandler Class1.btn1.Click, AddressOf btn1_Click
      AddHandler Class1.btn2.Click, AddressOf btn2_Click
      AddHandler Class1.btn3.Click, AddressOf btn3_Click
      AddHandler Class1.btn4.Click, AddressOf btn4_Click


   End Sub

   Private Sub btn1_Click
   End Sub

   Private Sub btn2_Click
   End Sub

   Private Sub btn3_Click
   End Sub

   Private Sub btn4_Click
   End Sub

End Class

There are 3 buttons in Class1 that create a new instance of Class2 and call the SetData passing a different value for iCode but the same created instance of Class1. The problem I have is you click btn3 for example, after the message box is displayed, it's handler is automatically called again, sometimes up to 4 times without me doing anything! I've experimented pressing the 4 buttons in Class1 and pressing any of the buttons handled in Class2 and sometimes the associated message box is displayed just the once (which is what should be happening), and on other occassions it can be displayed multiple times.

Can someone elighten me as to what's wrong with my code?

Thanks in advance

Old January 22nd, 2006, 07:32 PM
Authorized User
Join Date: Jan 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts

Before someone replies, my silly mistake was to not add in the example the handler signatures (ByVal sender As Object, ByVal e As System.EventArgs) for each button handler. Take it as read that I have done this in the class.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Incl certain fields if they appear multiple times SpyderSL Access VBA 1 November 4th, 2008 12:52 PM
Date on report called from multiple forms mean34dean Access 7 April 23rd, 2008 09:24 AM
same records shown multiple times alie VB Databases Basics 1 March 8th, 2006 10:13 AM
print multiple times..multiple rows... abhit_kumar JSP Basics 3 January 18th, 2005 07:11 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.