Hello
I would like to be able determine how many times the user has been click one button. Does any one how I could able to count how many times the button has been click. Note: No Timer
thank you
How to Count number of button has been Click?
Started by
Guest_roger_*
, May 28 2006 05:33 AM
4 replies to this topic
#1
Guest_roger_*
Posted 28 May 2006 - 05:33 AM
Guest_roger_*
|
|
|
#2
Posted 31 May 2006 - 05:49 PM
So every time a user clicks a certain button you would like to count the clicks? Why don't you create a global variable and then add one to it every time the button is clicked?
#3
Posted 01 June 2006 - 04:52 AM
Even better, from an OOP perspective, would be to inherit the Button class, override OnClick, and keep track of it in there. You could expose a ReadOnly Property to show the count.
But, yeah, you could just store it in a global.
But, yeah, you could just store it in a global.
#4
Posted 01 June 2006 - 11:00 AM
Yup, either option would work. I think the proper way to do it would be in a class but the quick and dirty way would be a global.
Why is it such a bad thing to use globals anyway?
Why is it such a bad thing to use globals anyway?
#5
Posted 01 June 2006 - 11:49 AM
Lop said:
Why is it such a bad thing to use globals anyway?
Globals are bad because they represent shared state. Shared state is bad because it means different pieces of code depend on each other. Obviously, you have to have shared state information. But, by encapsulating it into a class who's job it is to track and update the information, you've centralized the logic associated with that shared state.
Now, that being said, globals aren't really such a bad thing - they're just something to watch out for. Sometimes, the convenience of a global is worth it. But, then again, it's usually not too hard to replace a global with something (if only slightly) better.
Back to the original question, I should've tried to flesh out why the number of clicks needed to be tracked. I suspect that road would lead us to a class who's job would be to take some action based on clicks - and that job should probably be moved out of the Form (where it no doubt lives right now). By proposing a ReadOnly Property to expose that information, I think I probably proposed splitting out the logic that deals with the number of clicks - and that's not normally a good thing.
Just moving the tracking information inside a subclassed Button isn't really the whole solution, but based on the info given - it was the best I had at the moment.


Sign In
Create Account

Back to top










