By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,058 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,058 IT Pros & Developers. It's quick & easy.

enhanced button control

P: 22
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
Share this Question
Share on Google+
8 Replies


100+
P: 1,646
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

P: 22
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

Expert 5K+
P: 8,434
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

P: 22
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

P: 22
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

100+
P: 1,646
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

100+
P: 1,646
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

100+
P: 1,646
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

Post your reply

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