Question Tracking user progress

peshuk

New member
Joined
Jul 12, 2013
Messages
4
Location
Barnsley, England
Programming Experience
1-3
Hi all,

Just a quick question on the best way to code a way of tracking the user of my application? My application is just a computer aid and all I want to do is track how many times a action has been done I.e number of times a button is clicked, then after a certain number has been reached then do something else!

Look forward to your comments

Sent from my GT-I9505 using Tapatalk 2
 
Basically, you just declare an Integer variable and increment it each time the action is performed. In the case of clicking a Button, you would handle the Click event an increment there. Each time you increment, test whether the variable has reached a threshold value and, when it has, do whatever is appropriate.
 
This may or may not be appropriate but you could even incorporate the functionality into a custom control, e.g.
Public Class ClickCounterButton
    Inherits Button

    Private clickCount As Integer = 0

    Public Property ClickCountThreshold() As Integer

    Public Event ClickCountThresholdReached As EventHandler

    Protected Overrides Sub OnClick(e As EventArgs)
        MyBase.OnClick(e)

        clickCount += 1

        If clickCount = ClickCountThreshold Then
            OnClickCountThresholdReached(EventArgs.Empty)
        End If
    End Sub

    Protected Overridable Sub OnClickCountThresholdReached(e As EventArgs)
        RaiseEvent ClickCountThresholdReached(Me, e)
    End Sub

End Class
If you add that class to your project and build, you can then add instance of the ClickCounterButton control to your form from the Toolbox. It will look and behave exactly like a regular Button except that you can set the ClickCountThreshold property in the designer and handle the ClickCountThresholdReached event. If you set the property to, say, 10 and then run the project, the event will be raised after you click the button 10 times.
 
Back
Top