Results 1 to 4 of 4

Thread: Incrementing a number

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Grand Rapids, MI.
    Posts
    74

    Incrementing a number

    This should be incredibly simple, and I don't know why I can't figure it out. I want my form to count the number of times a button has been clicked. As far as I can tell, Visual Basic has no increment operator, which is really stupid.

    vb Code:
    1. Private Sub Form_Load()
    2. Dim intCounter As Integer
    3. intCounter = 0
    4. End Sub
    5.  
    6. Private Sub Command1_Click()
    7. intCounter = intCounter + 1
    8. End Sub

    I've also tried different operators that work in other programming languages, such as intCounter++ and intCounter+=1, but none of them seem to work. Why doesn't this work? It's embarrassing that I can't figure this out.

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Incrementing a number

    The way you're incrementing the number is correct. It's how you've declared your variable. Try this

    vb Code:
    1. 'Delcare this at the top of your form
    2. Dim intCounter As Integer
    3.  
    4. Private Sub Form_Load()
    5. intCounter = 0
    6. End Sub Private
    7.  
    8. Sub Command1_Click()
    9. intCounter = intCounter + 1
    10. End Sub

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Incrementing a number

    Use Option Explicit in order to minimize occurrence, if not totally avoid, such errors.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Grand Rapids, MI.
    Posts
    74

    Re: Incrementing a number

    That seems to work...

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