Incremental Counting

Hi, I've got a form with a 70 check boxes on it and 70 corresponding text boxes on it.  They are both control arrays.  I have coded them so that when a check box is clicked the corresponding text box next to it becomes visible.  Now what I want to do is have a number appear in the text box starting with 1 and increment up by 1 each time another check box on the form is clicked.  Thus, if a user clicked on 5 check boxes there would be 5 text boxes visible with the numbers 1 through 5 in the order that they were clicked.  I took a shot at this but only got the number 1 to appear over and over again.  I can't figure how to get a number to increment by 1 on this form.  Any help would be appreciated.  Thanks a bunch.
Who is Participating?
viktornetConnect With a Mentor Commented:
i think there is a better way, but i dont have VB so i can't test it..

you can do something like this..

for i = 1 to controls.count
  if controls(i) is CheckBox and controls(i).visible then count=count+1
next i

this is more of a pseudo-code...

If the variable 'cnt' is declared within the click event it will be reinitialized every time a check box is selected and the value would always be 1. Perhaps this is where you were experiencing a problem

Option Explicit
Dim cnt

Private Sub Check1_Click(Index As Integer)

If Check1(Index).Value = 1 Then
    cnt = cnt + 1
    Text1(Index).Text = cnt
    Text1(Index).Visible = True
End If

End Sub

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.