Solved

clicks property

Posted on 2004-10-17
9
168 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now