472,958 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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 4879
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Keith | last post by:
Just looking for some ideas here. What is the best way to count how many times an image has been clicked? I have an image gallery on a site and want to count how many times each image has been...
3
by: Megan | last post by:
hi everybody- i'm having a counting problem i hope you guys and gals could give me some help with. i have a query that retrieves a bevy of information from several different tables. first let...
7
by: sathyashrayan | last post by:
Group, Following function will check weather a bit is set in the given variouble x. int bit_count(long x) { int n = 0; /* ** The loop will execute once for each bit of x set,
7
by: moondaddy | last post by:
I have a user control being used instead of a frame page. when the user clicks on a menu item I need to send the ID (integer value) of that menu as a parameter in the postback of the user control...
1
by: Jerry | last post by:
We have a 10-question quiz for kids, each question being a yes or no answer using radio selections. I'd like to keep a current total of yes's and no's at the bottom of the quiz (if the user selects...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
5
by: sololoquist | last post by:
#define COUNT_UP #include <stdio.h> #define N 10 int main() { int i; #ifdef COUNT_UP for (i = 0; i < N; i++)
1
by: prophet | last post by:
I was on a page the other day (sorry, can not remember which one) and I saw something that I thought was neat. On the link page to other web pages there was an updated number of times that users...
3
by: bupanda | last post by:
I want to write a code for one of my command buttons (cmdCalculate) and that it shows the number of times it has been clicked in the lblGroupCount. I went through some books and I found this two...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.