clicks property

Hi, ineed to count how many time a button was clicked. I know that clicks property can do that count, the question is how do i get te clicks property , i have button1. ? - the clicks property is not in the list ?do i need to add a class or  import something, to get it displayed ?

Please help,
thanks,
Gipsy
GipsyAsked:
Who is Participating?
 
FSA7Connect With a Mentor Commented:
Hi Gipsy,

In the user control, you need to create a new public event, like:

    Public Event TestEvent()

Then in the Button1_Click event, you raise that event:


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

        clicked = clicked + 1

        RaiseEvent TestEvent()

    End Sub


Now any code can catch this event.  So back in your main application,
BtnEnhanced1_Click, instead of handling BtnEnhanced1.Click, should handle
BtnEnhanced1.TestEvent:

    Private Sub BtnEnhanced1_Click() Handles BtnEnhanced1.TestEvent

        Label1.Text = BtnEnhanced1.clickcount

    End Sub

Notice that this Sub takes no parameters because that's how TestEvent is
defined: no parameters.  Anyway, set up this way, clicking on the user
control's button will trigger this code.

Let me know if that works.
0
 
ShauliCommented:
Use the Click EVENT of the control you want to watch, as in the code below, where a command button is being counted for clicks.
Locate a command button (Command1) and a label control (Label1) on your form and paste the code below:


Option Explicit
Dim ButtonClicked As Long

Private Sub Command1_Click()
ButtonClicked = ButtonClicked + 1
Label1.Caption = ButtonClicked
End Sub

Private Sub Form_Load()
ButtonClicked = 0
End Sub

S
0
 
jimbobmcgeeCommented:
If you don't want an additional label or variable, you could adapt the above code to write to the Tag property of your command button, e.g.:

   Private Sub Command1_Click()
      Command1.Tag = Command1.Tag + 1
   End Sub

   Private Sub Form_Load()
      Command1.Tag = 0
   End Sub

   Private Sub ShowClicks
      MsgBox Command1.Caption & " has been clicked " & Command1.Tag & " times."
   End Sub

HTH

J.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
GipsyAuthor Commented:
thanks,
but i need to have a property rather than a procedure getting the number of times the button was clicked and thats why i needed a clicks property.
0
 
GipsyAuthor Commented:
Dim ButtonClicked As Long = 0

    Property count() As Long
        Get
            count = ButtonClicked
        End Get
        Set(ByVal Value As Long)
            ButtonClicked = ButtonClicked + 1
        End Set
    End Property

do you think this property will work and how can i test it within the program
0
 
jimbobmcgeeCommented:
You are going to need _some_ procedure to increment a click counter.  Unless you are creating your own button-style class...

The simplest method is still going to be to create a command button on your form and use:

    Sub Command1_Click

         Command1.Tag = Command1.Tag + 1

         'YOUR BUTTON CLICK CODE HERE

    End Sub

Then, if you need a property for the number of times Command1 has been clicked, you can use Command1.Tag as that property.

Perhaps we might be able to help you more if we knew exactly what you are trying to acheive (and why you feel you need a .Clicks property)...

HTH

J.
0
 
GipsyAuthor Commented:
I am developing my own button control, that has a property which tracks how many times it has been clicked. and then i need to test it in the program.

Becuase i think i cant use sub within a property i thought that by having clicks property the number of times can be calculated that way.

0
 
GipsyAuthor Commented:
Hi,
i agree i will need a procedure to increment the count. And i have got the click procedure for the control within the control code. it increments the ButtonClicked. And then i want to pass it over to the count1 property. I think my property and click sub are not talking to each other. Can you please assist, thanks


Dim ButtonClicked As Long = 0
    Property count1() As Long
        Get
            count1 = ButtonClicked
        End Get
        Set(ByVal Value As Long)
            ButtonClicked = Value
        End Set
    End Property

    Private Sub Button1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Resize
        Button1.Height = Me.Height
        Button1.Width = Me.Width
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ButtonClicked = ButtonClicked + 1
    End Sub
0
 
GipsyAuthor Commented:
Wow, that seems to work !

Thank you soo much, i gave up on idea that some one will be able to help me with this question !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.