473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

enhanced button control

I have built an enhanced button control which I want to use to capture the number of times the button has been clicked. I have added the new control to a test program but cannot get it to work. The code for the enhanced control is as follows:

Private Sub EnhBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnhBtn.Click
End Sub
Public Property totclicks() As Integer
Get
Dim n As Integer
totclicks = n + 1
End Get
Set(ByVal Value As Integer)
totclicks = Value
End Set
End Property

End Class

The code for the test program is:
Private Sub EnhButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EnhButton1.Click
Label2.Text = (EnhButton1.totclicks.ToString)
End Sub
End Class

Thanks in advance for all your help!!
Nov 17 '06 #1
8 2161
willakawill
1,646 1GB
I have built an enhanced button control which I want to use to capture the number of times the button has been clicked. I have added the new control to a test program but cannot get it to work. The code for the enhanced control is as follows:

Private Sub EnhBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnhBtn.Click
End Sub
Public Property totclicks() As Integer
Get
Dim n As Integer
totclicks = n + 1
End Get
Set(ByVal Value As Integer)
totclicks = Value
End Set
End Property

End Class

The code for the test program is:
Private Sub EnhButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EnhButton1.Click
Label2.Text = (EnhButton1.totclicks.ToString)
End Sub
End Class

Thanks in advance for all your help!!
Hi. This is a vb forum and you are using .NET
I will do my best to assist you anyway and you will have to translate any differences yourself.

Property get and set protect your variables from direct access so that you can run checks on what is being assigned and read. The actual values will be stored in a variable declared as private in your class module
In this particular instance you would declare something like
Expand|Select|Wrap|Line Numbers
  1. Private intTotalClicks As Integer
  2.  
In the onclick event you would increment this variable by one;
Expand|Select|Wrap|Line Numbers
  1. intTotalClicks = intTotalClicks + 1
  2.  
If you wish to seed this variable with a starting value of greater that 0 or if you wish to reset the button to 0 you would use the Set property
Expand|Select|Wrap|Line Numbers
  1. Set(ByVal Value As Integer)
  2.       intTotalClicks = Value
  3. End Set
  4.  
And when you wish to retrieve the number of clicks you would use the Get property
Expand|Select|Wrap|Line Numbers
  1. Get
  2. totclicks = intTotalClicks
  3. End Get
  4.  
Hope this helps
Nov 17 '06 #2
Hi. This is a vb forum and you are using .NET
I will do my best to assist you anyway and you will have to translate any differences yourself.

Property get and set protect your variables from direct access so that you can run checks on what is being assigned and read. The actual values will be stored in a variable declared as private in your class module
In this particular instance you would declare something like
Expand|Select|Wrap|Line Numbers
  1. Private intTotalClicks As Integer
  2.  
In the onclick event you would increment this variable by one;
Expand|Select|Wrap|Line Numbers
  1. intTotalClicks = intTotalClicks + 1
  2.  
If you wish to seed this variable with a starting value of greater that 0 or if you wish to reset the button to 0 you would use the Set property
Expand|Select|Wrap|Line Numbers
  1. Set(ByVal Value As Integer)
  2.       intTotalClicks = Value
  3. End Set
  4.  
And when you wish to retrieve the number of clicks you would use the Get property
Expand|Select|Wrap|Line Numbers
  1. Get
  2. totclicks = intTotalClicks
  3. End Get
  4.  
Hope this helps
Thanks for your help! Please accept my apologies for posting to the wrong forum. I use both .NET 2003 and VB 2005 and sometimes get confused! I will also post to the correct forum. Again, my thanks and apologies.
Nov 17 '06 #3
Killer42
8,435 Expert 8TB
Thanks for your help! Please accept my apologies for posting to the wrong forum. I use both .NET 2003 and VB 2005 and sometimes get confused! I will also post to the correct forum. Again, my thanks and apologies.
Of course, if you got the right answer, then by any sensible definition it's the right forum. :)

Let us know whether it works out, huh? (You can just post another reply to this thread, we'll see it.)
Nov 19 '06 #4
I am still havingn problems with this - I can get the counter to increase by one for a button click, but I cannot get the clicks stored so they will be used to increment the next button click.
I have done the following code:
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim totclicks As Integer
Dim n As Integer
Do
totclicks = n + 1
Loop While n > 0
Button1.Text = totclicks
End Sub
End Class
I an new to programming, and have never had to store any result so it can be used the next time the program is run.

As always, thanks for all the help you haveprovided to a novice!
Nov 19 '06 #5
I am still havingn problems with this - I can get the counter to increase by one for a button click, but I cannot get the clicks stored so they will be used to increment the next button click.
I have done the following code:
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim totclicks As Integer
Dim n As Integer
Do
totclicks = n + 1
Loop While n > 0
Button1.Text = totclicks
End Sub
End Class
I an new to programming, and have never had to store any result so it can be used the next time the program is run.

As always, thanks for all the help you haveprovided to a novice!

I GOT IT TO WORK!! I wrote a function to store the new value and that did the trick!!
Nov 19 '06 #6
willakawill
1,646 1GB
I GOT IT TO WORK!! I wrote a function to store the new value and that did the trick!!
To avoid confusion, all vb after vb6 is .NET
Interesting that you completely ignored my code and "Got it to work". I recommend that you revisit this project and look at the way I have coded it otherwise you will encounter monumental headaches in the very near future with your coding :)
Nov 19 '06 #7
willakawill
1,646 1GB
I am still havingn problems with this - I can get the counter to increase by one for a button click, but I cannot get the clicks stored so they will be used to increment the next button click.
I have done the following code:
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim totclicks As Integer
Dim n As Integer
Do
totclicks = n + 1
Loop While n > 0
Button1.Text = totclicks
End Sub
End Class
I an new to programming, and have never had to store any result so it can be used the next time the program is run.

As always, thanks for all the help you haveprovided to a novice!
The code you provided would never work. The loop will never loop even though it is not required to. Your code should look like this;
Expand|Select|Wrap|Line Numbers
  1. Private intTotalClicks As Integer
  2.  
  3. Private Sub EnhBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnhBtn.Click
  4.    intTotalClicks = intTotalClicks + 1
  5.    EnhBtn.Text = intTotalClicks
  6. End Sub
  7. Public Property totclicks() As Integer
  8.    Get
  9.       totclicks = intTotalClicks
  10.    End Get
  11.    Set(ByVal Value As Integer)
  12.       intTotalClicks = Value
  13.    End Set
  14. End Property
  15.  
  16. End Class
  17.  
  18.  
Nov 19 '06 #8
willakawill
1,646 1GB
I GOT IT TO WORK!! I wrote a function to store the new value and that did the trick!!
BTW for those of us interested in doing this in VB6, declare an integer in the form module;

Expand|Select|Wrap|Line Numbers
  1. Private intTotalClicks As Integer
  2.  
and put a button on your form. Call it cmdTotalClicks
At the Click event;
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdTotalClicks_Click()
  2.     intTotalClicks = intTotalClicks + 1
  3.     cmdTotalClicks.Caption = intTotalClicks & " Clicks"
  4. End Sub
  5.  
Nov 19 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jo Vermeulen | last post by:
Hello, I was wondering if it's possible to add a condition to the enhanced for loop. This is an example of an enhanced for loop: LinkedList<MyClass> children = new LinkedList<MyClass>();...
2
by: Chuck Bowling | last post by:
The subject line says it all. Anybody know if the RichTextBox control supports enhanced metafiles?
3
by: drodrig | last post by:
My apologies if this question has been asked an answered. I am looking for a tkinter grid control or enhanced listbox that can act as a "receipt" for a cash register program. I would like the...
7
by: Ben Sizer | last post by:
A simple question - can anybody give a short example of how these work and what they are good for? I've read PEP 342 and the associated bit in the What's New section and it's still all Greek to me....
0
by: lab3terch | last post by:
I have built an enhanced button control which I want to use to capture the number of times the button has been clicked. I have added the new control to a test program but cannot get it to work. The...
0
by: lab3terch | last post by:
I am using Visual Studio.NET 2003 and have built a enhanced button control (enhbutton) to capture the number of times the button has been clicked. I did the code and did a build. I then added a test...
1
by: | last post by:
I use a variety of controls made by a variety of vendors, including Microsoft. In general the level of development on gridview-like presentational controls is very impressive. Telerik, Inc's...
0
by: Roberto Kohler | last post by:
I created an enhanced Button Control in ASP NET 2.0 to add a delete confirmation message and to disable the button if the user does not have access. The new button control has a "ConfirmMessage"...
3
by: Dave Angel | last post by:
I have implemented the 'A list apart' styleswitcher which works great. I now have: - A permanent stylesheet - A normal contrast stylesheet - A high contrast stylesheet The switcher simply...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.