Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Visual Basic Programming

Visual Basic Programming Discussion forum for Visual Basic, an event driven programming language and associated development environment from Microsoft for its COM programming model.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-28-2006, 08:33 AM
roger roger is offline
Newbie
 
Join Date: May 2006
Posts: 16
Rep Power: 9
roger is on a distinguished road
Arrow How to Count number of button has been Click?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-31-2006, 08:49 PM
Crane's Avatar   
Crane Crane is offline
Programming Expert
 
Join Date: Nov 2005
Posts: 399
Rep Power: 13
Crane is on a distinguished road
Default

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-01-2006, 07:52 AM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Rep Power: 10
brackett is on a distinguished road
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-01-2006, 02:00 PM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,135
Rep Power: 16
Lop is on a distinguished road
Default

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?
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-01-2006, 02:49 PM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Rep Power: 10
brackett is on a distinguished road
Default

Quote:
Originally Posted by Lop
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows XP Tricks & Tips!!!!..new ones. pranky Tutorials 9 08-23-2008 03:22 PM
Java:Tutorial - Tic-Tac-Toe John Java Tutorials 25 02-27-2008 06:41 PM
Disable a button reachpradeep ASP, ASP.NET and Coldfusion 1 03-03-2007 02:35 PM
Number Cloning Ronin Java Help 3 12-21-2006 07:23 AM
Button Click Lop C# Programming 5 05-23-2006 09:06 AM


All times are GMT -5. The time now is 12:03 AM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads