Results 1 to 4 of 4

Thread: consecutive numbers

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    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.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281
    Thanks Peet!,

    Works great

  4. #4
    Megatron
    Guest
    Make sure to include the Randomize statement to select a new seed value.

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