-
consecutive numbers
Hi,
I have a simple program like this:
Private Sub Command1_Click()
Dim the_number As Integer
the_number = Int(Rnd * 50)
Text1 = the_number
End Sub
So say Text1 comes up as '23'.
Then, when I click another button, command2, I want the sum of all numbers, from 1 to 22 (1+2+3+4...etc..+22) to appear in Text2.
Does anyone know how I could do this? I think it's some sort of Loop or something, but I'm not sure how.
-
Code:
Private Sub Command1_Click()
Dim the_number As Integer
Dim lSum As Long
Dim l As Long
the_number = Int(Rnd * 50)
Text1 = the_number
For l = 1 To CLng(Text1.Text) - 1
lSum = lSum + l
Next l
Text2.Text = lSum
End Sub
peet
-
Thanks Peet!,
Works great
-
Make sure to include the Randomize statement to select a new seed value.