Results 1 to 5 of 5

Thread: [RESOLVED] [2008] Adding The Number 1 Onto A Variable

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Resolved [RESOLVED] [2008] Adding The Number 1 Onto A Variable

    I need to keep count of things in the app I'm working on. When the user clicks a button it adds 1 onto the variable "count".

    Here's the code that doesn't work:
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim count = 0
            count = count + 1
            Label1.Text = count.ToString()
        End Sub
    Ahhhhh! This is really bugging me! Please help! Any of it is greatly appreciated!

  2. #2
    Addicted Member ThatSamiam's Avatar
    Join Date
    Apr 2007
    Posts
    128

    Re: [2008] Adding The Number 1 Onto A Variable

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Static count = 0
    count += 1
    Label1.Text = count.ToString()
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: [2008] Adding The Number 1 Onto A Variable

    Wow! Thanks for the really quick reply - it's working now!
    Thanks a lot!

  4. #4
    Addicted Member ThatSamiam's Avatar
    Join Date
    Apr 2007
    Posts
    128

    Re: [RESOLVED] [2008] Adding The Number 1 Onto A Variable

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
             Button1.Tag = (CInt(Button1.Tag) + 1).ToString
            Label1.Text = count.ToString()
        End Sub

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Question Re: [2008] Adding The Number 1 Onto A Variable

    Quote Originally Posted by Louix
    Wow! Thanks for the really quick reply - it's working now!
    Thanks a lot!
    That's great that it is working, but do you know & understand why it works? (or care to know?)

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width