14/6/12

FOR NEXT Cycle. Counters and accumulators

Counter

C=C+1

Accumulator

C=C+N

Example:

  Input 10 numbers and report how many positive and negative are here. 



Private Sub CommandButton1_Click()
Dim a As Integer
Dim c As Integer
dim d as integer
Dim i As Integer
For i = 1 To 10
a= InputBox("Input a number")
If a> 0 Then
c = c + 1
Else
d=d+1
End If
Next i
MsgBox ("We have " & c & "  positive numbers")
MsgBox ("We have " & d & "  negative numbers")
End Sub

Use userform to solve this problem.