Click to See Complete Forum and Search --> : it doesn't add up!


silverhour
September 26th, 2001, 01:19 PM
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.

MKSa
September 26th, 2001, 01:33 PM
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.

DSJ
September 26th, 2001, 01:37 PM
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

silverhour
September 26th, 2001, 01:44 PM
like I said, I feel stupid now :P Thanks for the help.