User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 391,548 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,520 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Views: 1682 | Replies: 8 | Solved
Closed Thread
Join Date: Jun 2006
Posts: 2
Reputation: jdm102984 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jdm102984 jdm102984 is offline Offline
Newbie Poster

Troubleshooting "click Counter" help Please

  #1  
Jun 26th, 2006
I'm new to VB...Really new. The main thing I am needing to accomplish is this program I am trying to make. It's just a counter. You click the button and it shows the number of clicks in the label. Well, There are 14 counters in the one program. But I can't get them to go past 1...I was hoping someone could take a look at it for me... and I hope I don't mess up the [] things lol Oh yea, it'd be used for counting cards lol

Private Sub Aces_Click()
Dim CounterVariable As Integer
CounterVariable = CounterVariable + 1
Label1 = CounterVariable
End Sub
Private Sub Eights_Click()
Dim CounterVariable8 As Integer
CounterVariable8 = CounterVariable8 + 1
Label8 = CounterVariable8
End Sub
Private Sub Fives_Click()
Dim CounterVariable5 As Integer
CounterVariable5 = CounterVariable5 + 1
Label5 = CounterVariable5
End Sub
Private Sub Fours_Click()
Dim CounterVariable4 As Integer
CounterVariable4 = CounterVariable4 + 1
Label4 = CounterVariable4
End Sub
Private Sub Jacks_Click()
Dim CounterVariable11 As Integer
CounterVariable11 = CounterVariable11 + 1
Label11 = CounterVariable11
End Sub
Private Sub Jokers_Click()
Dim CounterVariable14 As Integer
CounterVariable14 = CounterVariable14 + 1
Label14 = CounterVariable14
End Sub
Private Sub Kings_Click()
Dim CounterVariable13 As Integer
CounterVariable13 = CounterVariable13 + 1
Label13 = CounterVariable13
End Sub
Private Sub Nines_Click()
Dim CounterVariable9 As Integer
CounterVariable9 = CounterVariable9 + 1
Label9 = CounterVariable9
End Sub
Private Sub Queens_Click()
Dim CounterVariable12 As Integer
CounterVariable12 = CounterVariable12 + 1
Label12 = CounterVariable12
End Sub
Private Sub Sevens_Click()
Dim CounterVariable7 As Integer
CounterVariable7 = CounterVariable7 + 1
Label7 = CounterVariable7
End Sub
Private Sub Sixs_Click()
Dim CounterVariable6 As Integer
CounterVariable6 = CounterVariable6 + 1
Label6 = CounterVariable6
End Sub
Private Sub Tens_Click()
Dim CounterVariable10 As Integer
CounterVariable10 = CounterVariable10 + 1
Label10 = CounterVariable10
End Sub
Private Sub Threes_Click()
Dim CounterVariable3 As Integer
CounterVariable3 = CounterVariable3 + 1
Label3 = CounterVariable3
End Sub
Private Sub Twos_Click()
Dim CounterVariable2 As Integer
CounterVariable2 = CounterVariable2 + 1
Label2 = CounterVariable2
End Sub

Thank you all in advance!
--Joshua
Last edited by jdm102984 : Jun 26th, 2006 at 1:45 am.
AddThis Social Bookmark Button
 
Join Date: Jun 2006
Posts: 67
Reputation: agrothe is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 9
agrothe's Avatar
agrothe agrothe is offline Offline
Junior Poster in Training

Re: "click Counter" help Please

  #2  
Jun 26th, 2006
Declare your variables at the form level, if you declare in the procedural level, they get reset each time the sub or function runs.
------------------------------------------------------------
ConnectNL Directory | NLTourist | Free eLearing Courses
 
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: "click Counter" help Please

  #3  
Jun 26th, 2006
You can declare them at the form level, or you could simply replace each occurance of Dim with Static. Static allows you to make a procedural variable, that will maintain it's value until manually reset (or the object in which it resides is destroyed). It's good programming etiquette to use static as opposed to declaring your variables at the form's scope, because in this case, you have no need or desire to use that same variable in a different procedure on the same form. This keeps structure and organization in your code, and doesn't use as much memory by having to span the variable to different procedures.
Last edited by Comatose : Jun 26th, 2006 at 10:01 am.
 
Join Date: Jun 2006
Posts: 2
Reputation: jdm102984 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jdm102984 jdm102984 is offline Offline
Newbie Poster

Re: "click Counter" help Please

  #4  
Jun 26th, 2006
Thank You both so much. I wish I could say I understood everything, but that'd be a lie. lol I did understand the part where I just had to switch DIM for Static, and it's working perfect. I think I am going to attempt a reset button. Which means you'll probably be hearing from me again, but I will give it a shot first. Once again thank you!

--Joshua
 
Join Date: May 2006
Posts: 24
Reputation: sosco is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
sosco's Avatar
sosco sosco is offline Offline
Newbie Poster

Re: "click Counter" help Please

  #5  
Jun 27th, 2006
it's easy. for example:
Dim CounterVariable14 As Integer
CounterVariable14 = CounterVariable14 + 1
Label14 = CounterVariable14
End Sub

when you press the button you want to add 1 to your variable(your counter). in the button property i see that you declare the varible: Dim CounterVariable14 As Integer. understood till here? but when ou declare it, it will have 0 value. so each time you will press the button your variblae will be: 0=0+1. each time the value of the varible in each button will be 1

so what you need is to declare the variable as public. you will have somehting like this at the begineing of the 'code window'

declare type
dim CounterVariable14 As Integer


Private Sub Jokers_Click()
CounterVariable14 = CounterVariable14 + 1
Label14 = CounterVariable14
End Sub
---------------------------
Modest Valentin, Ticu
IATAR Studio

http://iatar.no-ip.org/
 
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: "click Counter" help Please

  #6  
Jun 27th, 2006
Right, but as per my previous post, this method is depreciated..... it's bad programming practice to put variables outside of their scope of intended use.....
 
Join Date: May 2006
Posts: 24
Reputation: sosco is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
sosco's Avatar
sosco sosco is offline Offline
Newbie Poster

Re: "click Counter" help Please

  #7  
Jun 27th, 2006
well... ne or not depreciated
i work in VB for about 7 years! i worked in many company in VB and i used variables declared like this! and nothing gone wrong!
---------------------------
Modest Valentin, Ticu
IATAR Studio

http://iatar.no-ip.org/
 
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 107
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: "click Counter" help Please

  #8  
Jun 27th, 2006
I've been working in VB for over a decade (10 years), Interfaced VB with RADIUS Servers, and Linux Side Perl with Sockets, and have been a senior programmer for a corporation doing VB..... I'm not here challenging your credentials (nor should you challenge mine) and while there may not be any errors in doing this kind of programming, it's poorly written code. Anybody who has written code in a language other than VB, understands very well that scope is a very important aspect to programming. Scope keeps variables maintained, and it saves space in RAM by not having to span multiple procedures. Fact is, if you don't need the variable outside of the procedure, you shouldn't declare it outside of the procedure..... it's bad programming practice.

While the solution you provided can/will work, professional code simply should not be written that way. My AIM here is to provide more than a solution..... it's to provide people with a solution that fits into proper programming style.

Now, I'm sorry if I offended you with my previous post negating your post, I understand and appreciate that you are being helpful, but it's important for programmers to understand that vital role of variables in scope.... which Is why I posted what I did.
Last edited by Comatose : Jun 27th, 2006 at 7:54 pm.
 
Join Date: May 2006
Posts: 24
Reputation: sosco is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
sosco's Avatar
sosco sosco is offline Offline
Newbie Poster

Re: "click Counter" help Please

  #9  
Aug 27th, 2006
Hi Comasote,

Sorry for this delay but i have and i am buisy right here.
If you afended me? Oh no.. stay easy.. i never thought about that! Just cose i have not tu much time, now.
---------------------------
Modest Valentin, Ticu
IATAR Studio

http://iatar.no-ip.org/
 
Closed Thread

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 9:02 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC