468,504 Members | 2,006 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,504 developers. It's quick & easy.

Counting times a control is clicked.

Al
Can anyone tell me if there's a way to return the amount
of times a button is "clicked"

I need to change text in a text box and that text changes
each time the button is clicked-up to 6 times with 6
different text values.

Thanks in anticipation.

Al@n
Nov 20 '05 #1
11 4620
"Al@n" <an*******@discussions.microsoft.com> wrote...
Can anyone tell me if there's a way to return the amount
of times a button is "clicked"


Is this a trick question :-) Wouldn't you just keep track by incrementing a
counter?
Nov 20 '05 #2
Create a module level variablle and increment it via the Buttons Click
event. Other than that, i'm not sure there's such a property.
"Al@n" <an*******@discussions.microsoft.com> wrote in message
news:33****************************@phx.gbl...
Can anyone tell me if there's a way to return the amount
of times a button is "clicked"

I need to change text in a text box and that text changes
each time the button is clicked-up to 6 times with 6
different text values.

Thanks in anticipation.

Al@n

Nov 20 '05 #3
* "Al@n" <an*******@discussions.microsoft.com> scripsit:
Can anyone tell me if there's a way to return the amount
of times a button is "clicked"

I need to change text in a text box and that text changes
each time the button is clicked-up to 6 times with 6
different text values.


\\\
Private Sub Button1_Click(...) Handles...
Static n As Integer
n = n + 1
Me.Label1.Text = n.ToString()
End Sub
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Hi Tom.

No, I dont think it is a trick question. The OP needs a static ( Shared )
integer doesent he/she ?, The problem is that the OP has asked an innocent
question, your mind has told you that there must be more to it !

BTW, I saw you struggling with J# the other day in the J# newsgroup, I was
also struggling with J# at the same time thats why I saw you there. It's a
pain from the documentation point of view isnt it ?

Regards - OHM

Tom Leylan wrote:
"Al@n" <an*******@discussions.microsoft.com> wrote...
Can anyone tell me if there's a way to return the amount
of times a button is "clicked"


Is this a trick question :-) Wouldn't you just keep track by
incrementing a counter?


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #5
"One Handed Man" <O_************************@BTInternet.com> wrote...
No, I dont think it is a trick question. The OP needs a static ( Shared )
integer doesent he/she ?, The problem is that the OP has asked an innocent
question, your mind has told you that there must be more to it !


I thought the OP needed to keep track of how many times a button on a form
was clicked. Any old integer property declared in the form will do it I
think but I could be wrong.
Nov 20 '05 #6
Al
Gents
What I'm trying to achieve is a simulation of a controlpanel used in
work-for training purposes.

In pushing a particular button a number of times it will alter the "display
panel" each click event until
interrupted by another button is clicked

I need to retain the number of clicks on the original button to recommence
the display at the point it was interrupted.

I'm sorry if the question seemed silly but am new to this game and couldn't
work out how to achieve my goal.

Thanks for the assistance offered

Al@n

"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"One Handed Man" <O_************************@BTInternet.com> wrote...
No, I dont think it is a trick question. The OP needs a static ( Shared ) integer doesent he/she ?, The problem is that the OP has asked an innocent question, your mind has told you that there must be more to it !


I thought the OP needed to keep track of how many times a button on a form
was clicked. Any old integer property declared in the form will do it I
think but I could be wrong.

Nov 20 '05 #7
"Al@n" <no*@thisdomain.co.uk> wrote...
Gents
What I'm trying to achieve is a simulation of a controlpanel used in
work-for training purposes.

In pushing a particular button a number of times it will alter the "display panel" each click event until
interrupted by another button is clicked

I need to retain the number of clicks on the original button to recommence
the display at the point it was interrupted.

I'm sorry if the question seemed silly but am new to this game and couldn't work out how to achieve my goal.

Thanks for the assistance offered


It isn't that your question is silly I just thought there must be more to
it. Each time a button is clicked you want to increment a variable to keep
track of the number of clicks right? You've surely assigned values to
variables in other places and you must have placed code in a click event at
some point. Isn't your solution a combination of these things?

I figure I must have something wrong. Place an integer variable/property on
your form and increment it in your button "click" handler.

I'm not ragging on you but "new" to programming or "new" to .Net? It's hard
to know how much detail to give in a response...
Nov 20 '05 #8
Well, Tom is right you could increment a form class level integer and
increment that, but using a static integer in the method is tidier I think.

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

Static Dim count As Integer = 0

count += 1

lblCount.Text = count.ToString

End Sub

Regards - OHM




Al@n wrote:
Gents
What I'm trying to achieve is a simulation of a controlpanel used in
work-for training purposes.

In pushing a particular button a number of times it will alter the
"display panel" each click event until
interrupted by another button is clicked

I need to retain the number of clicks on the original button to
recommence the display at the point it was interrupted.

I'm sorry if the question seemed silly but am new to this game and
couldn't work out how to achieve my goal.

Thanks for the assistance offered

Al@n

"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"One Handed Man" <O_************************@BTInternet.com> wrote...
No, I dont think it is a trick question. The OP needs a static ( Shared ) integer doesent he/she ?, The problem is that the OP has asked an
innocent question, your mind has told you that there must be more
to it !


I thought the OP needed to keep track of how many times a button on
a form was clicked. Any old integer property declared in the form
will do it I think but I could be wrong.


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #9
I am pretty certain the OP posted something about needing to reset it after
6 presses or something like that. That logic can also be written into the
click handler but roughly 90% of the postings suggest that placing business
logic into an event handler is not a great idea. And if he wants to click
Button2 to have the value reset then what?

I still don't know what he's ultimately trying to do but I will suggest (as
an alternative) that he model his app in a class designed to
handle/process/maintain whatever states his "little machine" needs to keep
track of.

Al@n: You can clearly scatter static variables throughout your UI code...
I'll recommend against it. Have you developed a class before? If you have
then it's time to do it again, if not, it might be a good time to consider
it. Your object will contain all the data related to itself, it can raise
events, etc., etc.

"One Handed Man" <O_************************@BTInternet.com> wrote in
message news:bv**********@sparta.btinternet.com...
Well, Tom is right you could increment a form class level integer and
increment that, but using a static integer in the method is tidier I think.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Static Dim count As Integer = 0

count += 1

lblCount.Text = count.ToString

End Sub

Regards - OHM

Al@n wrote:
Gents
What I'm trying to achieve is a simulation of a controlpanel used in
work-for training purposes.

In pushing a particular button a number of times it will alter the
"display panel" each click event until
interrupted by another button is clicked

I need to retain the number of clicks on the original button to
recommence the display at the point it was interrupted.

I'm sorry if the question seemed silly but am new to this game and
couldn't work out how to achieve my goal.

Thanks for the assistance offered

Al@n

"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"One Handed Man" <O_************************@BTInternet.com> wrote...

No, I dont think it is a trick question. The OP needs a static (

Shared )
integer doesent he/she ?, The problem is that the OP has asked an
innocent question, your mind has told you that there must be more
to it !

I thought the OP needed to keep track of how many times a button on
a form was clicked. Any old integer property declared in the form
will do it I think but I could be wrong.


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com

Nov 20 '05 #10
On reflection, I think I agree with you, a Private Integer field is probably
better than using a static in the event handler, where you put it is another
matter and therefore whether it is static or not. If the button is wrapped
then you might want a property of the class you wrap it in which internally
refers to a static field. If not then at form level as an integer.

OHM

Tom Leylan wrote:
I am pretty certain the OP posted something about needing to reset it
after 6 presses or something like that. That logic can also be
written into the click handler but roughly 90% of the postings
suggest that placing business logic into an event handler is not a
great idea. And if he wants to click Button2 to have the value reset
then what?

I still don't know what he's ultimately trying to do but I will
suggest (as an alternative) that he model his app in a class designed
to handle/process/maintain whatever states his "little machine" needs
to keep track of.

Al@n: You can clearly scatter static variables throughout your UI
code... I'll recommend against it. Have you developed a class
before? If you have then it's time to do it again, if not, it might
be a good time to consider it. Your object will contain all the data
related to itself, it can raise events, etc., etc.

"One Handed Man" <O_************************@BTInternet.com> wrote in
message news:bv**********@sparta.btinternet.com...
Well, Tom is right you could increment a form class level integer and
increment that, but using a static integer in the method is tidier I
think.

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

Static Dim count As Integer = 0

count += 1

lblCount.Text = count.ToString

End Sub

Regards - OHM

Al@n wrote:
Gents
What I'm trying to achieve is a simulation of a controlpanel used in
work-for training purposes.

In pushing a particular button a number of times it will alter the
"display panel" each click event until
interrupted by another button is clicked

I need to retain the number of clicks on the original button to
recommence the display at the point it was interrupted.

I'm sorry if the question seemed silly but am new to this game and
couldn't work out how to achieve my goal.

Thanks for the assistance offered

Al@n

"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
"One Handed Man" <O_************************@BTInternet.com>
wrote...

> No, I dont think it is a trick question. The OP needs a static (
> Shared ) integer doesent he/she ?, The problem is that the OP has
> asked an innocent question, your mind has told you that there
> must be more to it !

I thought the OP needed to keep track of how many times a button on
a form was clicked. Any old integer property declared in the form
will do it I think but I could be wrong.


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #11
Al
Tom

Thanks to the advice given by yourself and OHM, I think I can sort out the
issue on my form.
I'm cetainly new to .Net and this is the first project I've attempted. I've
some experience in VBA, particularly user input in Word.
Thanks both again

Al@n

"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl...
I am pretty certain the OP posted something about needing to reset it after 6 presses or something like that. That logic can also be written into the
click handler but roughly 90% of the postings suggest that placing business logic into an event handler is not a great idea. And if he wants to click
Button2 to have the value reset then what?

I still don't know what he's ultimately trying to do but I will suggest (as an alternative) that he model his app in a class designed to
handle/process/maintain whatever states his "little machine" needs to keep
track of.

Al@n: You can clearly scatter static variables throughout your UI code...
I'll recommend against it. Have you developed a class before? If you have then it's time to do it again, if not, it might be a good time to consider
it. Your object will contain all the data related to itself, it can raise
events, etc., etc.

"One Handed Man" <O_************************@BTInternet.com> wrote in
message news:bv**********@sparta.btinternet.com...
Well, Tom is right you could increment a form class level integer and
increment that, but using a static integer in the method is tidier I

think.

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

Static Dim count As Integer = 0

count += 1

lblCount.Text = count.ToString

End Sub

Regards - OHM

Al@n wrote:
Gents
What I'm trying to achieve is a simulation of a controlpanel used in
work-for training purposes.

In pushing a particular button a number of times it will alter the
"display panel" each click event until
interrupted by another button is clicked

I need to retain the number of clicks on the original button to
recommence the display at the point it was interrupted.

I'm sorry if the question seemed silly but am new to this game and
couldn't work out how to achieve my goal.

Thanks for the assistance offered

Al@n

"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
> "One Handed Man" <O_************************@BTInternet.com> wrote...
>
>> No, I dont think it is a trick question. The OP needs a static (
Shared )
>> integer doesent he/she ?, The problem is that the OP has asked an
>> innocent question, your mind has told you that there must be more
>> to it !
>
> I thought the OP needed to keep track of how many times a button on
> a form was clicked. Any old integer property declared in the form
> will do it I think but I could be wrong.


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


Nov 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Keith | last post: by
3 posts views Thread by Megan | last post: by
7 posts views Thread by sathyashrayan | last post: by
7 posts views Thread by moondaddy | last post: by
1 post views Thread by Jerry | last post: by
5 posts views Thread by sololoquist | last post: by
1 post views Thread by prophet | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.