Solved

clicks property

Posted on 2004-10-17
9
170 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:Gipsy
9 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 12332106
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
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12337253
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
 

Author Comment

by:Gipsy
ID: 12346424
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:Gipsy
ID: 12355146
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
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12356702
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
 

Author Comment

by:Gipsy
ID: 12356853
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
 

Author Comment

by:Gipsy
ID: 12370111
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
 

Accepted Solution

by:
FSA7 earned 100 total points
ID: 12442594
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
 

Author Comment

by:Gipsy
ID: 12442616
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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question