CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2001
    Location
    Canada
    Posts
    2

    it doesn't add up!

    This is really wierd, and probably simple, but I can't get my counter to add more than once. It's simple code

    Private Sub Form_Load()
    Dim countnum As Integer
    countnum = 0
    End Sub

    Private Sub cmdadd1_Click()
    countnum = countnum + 1
    lblcount.Caption = countnum
    End Sub

    my form is simply a command button (cmdadd1) and a label (lblcount). It works once, when I click on cmdadd1, but only once, regardless of how many times I click after that.
    I'll feel stupid when you tell me whats wrong, but I already feel stupid for not being able to figure it out on my own.


  2. #2
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: it doesn't add up!


    Your code should give an error in the mdadd1_Click sub because countnum was not defined. Any way to make your code work remove the lineDim countnum as Integer


    from the form_load sub and put it in the General Declarations.


  3. #3
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: it doesn't add up!

    In your example, there are two countnum variables... one local to FormLoad and one local to cmdAdd1_Click() try this instead...


    option Explicit
    Dim x as Integer

    private Sub Command1_Click()
    x = x + 1
    Label1.Caption = x
    End Sub





  4. #4
    Join Date
    Sep 2001
    Location
    Canada
    Posts
    2

    Re: it doesn't add up!

    like I said, I feel stupid now :P Thanks for the help.


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

Featured