Results 1 to 4 of 4

Thread: problem with nested counter controlled repetition

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    2
    The following code:

    Private Sub cmdPrint_Click()
    Dim count As Integer
    Dim number As Integer
    Dim counter As Integer

    count = 1
    number = 0
    counter = 0

    For count = 1 To 10
    Do
    Print "*"
    number = number + 1
    counter = counter + 1
    Loop While number <> counter
    Print
    Next count

    End Sub

    is supposed to produce the following shape:

    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********

    Instead it produces thus:

    *
    *
    *
    *
    *
    *
    *
    *
    *
    *

    please help.

  2. #2
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    Here's some coed that does what you want
    The reason your code can't produce the correct result is because every time you print"* in goes down one line

    Private Sub Command1_Click()

    Dim count As Integer




    For count = 1 To 10
    Select Case count
    Case 1
    Print "*"
    Case 2
    Print "**"
    Case 3
    Print "***"
    End Select
    Next count


    End Sub

  3. #3
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362

    eh? ***?


    Code:
    Dim i%
    
        For i = 1 To 10
            Print String(i, "*")
        Next

    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    tumblingdown@hotmail.com

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  4. #4
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    and why is this in chit-chat?


    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    tumblingdown@hotmail.com

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

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