Gipsy
asked on
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
Please help,
thanks,
Gipsy
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.
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.
ASKER
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.
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.
ASKER
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
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
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.
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.
ASKER
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.
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.
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 !
Thank you soo much, i gave up on idea that some one will be able to help me with this question !
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