enhanced button control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lab3terch
    New Member
    • Oct 2006
    • 22

    #1

    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(By Val sender As System.Object, ByVal e As System.EventArg s) 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_Clic k(ByVal sender As Object, ByVal e As System.EventArg s) Handles EnhButton1.Clic k
    Label2.Text = (EnhButton1.tot clicks.ToString )
    End Sub
    End Class

    Thanks in advance for all your help!!
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by lab3terch
    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(By Val sender As System.Object, ByVal e As System.EventArg s) 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_Clic k(ByVal sender As Object, ByVal e As System.EventArg s) Handles EnhButton1.Clic k
    Label2.Text = (EnhButton1.tot clicks.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
    Code:
    Private intTotalClicks As Integer
    In the onclick event you would increment this variable by one;
    Code:
    intTotalClicks = intTotalClicks + 1
    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
    Code:
    Set(ByVal Value As Integer)
          intTotalClicks = Value
    End Set
    And when you wish to retrieve the number of clicks you would use the Get property
    Code:
    Get
    totclicks = intTotalClicks
    End Get
    Hope this helps

    Comment

    • lab3terch
      New Member
      • Oct 2006
      • 22

      #3
      Originally posted by willakawill
      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
      Code:
      Private intTotalClicks As Integer
      In the onclick event you would increment this variable by one;
      Code:
      intTotalClicks = intTotalClicks + 1
      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
      Code:
      Set(ByVal Value As Integer)
            intTotalClicks = Value
      End Set
      And when you wish to retrieve the number of clicks you would use the Get property
      Code:
      Get
      totclicks = intTotalClicks
      End Get
      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.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by lab3terch
        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.)

        Comment

        • lab3terch
          New Member
          • Oct 2006
          • 22

          #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(B yVal sender As Object, ByVal e As System.EventArg s) 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!

          Comment

          • lab3terch
            New Member
            • Oct 2006
            • 22

            #6
            Originally posted by lab3terch
            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(B yVal sender As Object, ByVal e As System.EventArg s) 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!!

            Comment

            • willakawill
              Top Contributor
              • Oct 2006
              • 1646

              #7
              Originally posted by lab3terch
              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 :)

              Comment

              • willakawill
                Top Contributor
                • Oct 2006
                • 1646

                #8
                Originally posted by lab3terch
                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(B yVal sender As Object, ByVal e As System.EventArg s) 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;
                Code:
                Private intTotalClicks As Integer
                
                Private Sub EnhBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnhBtn.Click
                   intTotalClicks = intTotalClicks + 1
                   EnhBtn.Text = intTotalClicks
                End Sub
                Public Property totclicks() As Integer
                   Get
                      totclicks = intTotalClicks
                   End Get
                   Set(ByVal Value As Integer)
                      intTotalClicks = Value
                   End Set
                End Property
                
                End Class

                Comment

                • willakawill
                  Top Contributor
                  • Oct 2006
                  • 1646

                  #9
                  Originally posted by lab3terch
                  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;

                  Code:
                  Private intTotalClicks As Integer
                  and put a button on your form. Call it cmdTotalClicks
                  At the Click event;
                  Code:
                  Private Sub cmdTotalClicks_Click()
                      intTotalClicks = intTotalClicks + 1
                      cmdTotalClicks.Caption = intTotalClicks & " Clicks"
                  End Sub

                  Comment

                  Working...