HI i need some help with looping

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DS2000
    New Member
    • Oct 2006
    • 1

    HI i need some help with looping

    I am creating a Number Generator program and it needs to look similar to this:

    1
    2 2
    3 3 3
    4 4 4 4

    The user inputs the number of rows. I have no idea how to space out my numbers in order for that to look like a piramid. The code I have so far is:

    Private Sub cmdShowTable_Cl ick()

    Dim a As String
    Dim num As Integer
    Me.Cls

    num = txtInput.Text

    For i = 1 To num
    a = ""
    For j = 1 To i
    a = a & " " & i
    Next j
    Print a
    Next i

    End Sub

    Please Help!
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by DS2000
    I am creating a Number Generator program and it needs to look similar to this:

    1
    2 2
    3 3 3
    4 4 4 4

    The user inputs the number of rows. I have no idea how to space out my numbers in order for that to look like a piramid. The code I have so far is:

    Private Sub cmdShowTable_Cl ick()

    Dim a As String
    Dim num As Integer
    Me.Cls

    num = txtInput.Text

    For i = 1 To num
    a = ""
    For j = 1 To i
    a = a & " " & i
    Next j
    Print a
    Next i

    End Sub

    Please Help!
    This will work:

    For i = 1 To num
    a = i
    j = 1
    Do While j < i
    a = a & i
    j = j + 1
    Loop
    For j = 1 To (1 + (num - i))
    a = " " & a
    Next j
    Print a
    Next i

    Comment

    Working...