Results 1 to 3 of 3

Thread: Loop command help

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4

    Loop command help

    Im learning visual basic and hopefully someone will be able to help out. I did the first part of my project now can someone please help me out with the second part

    Project1: Make a program that will print a triangle of stars. User must be able to input amount of stars on bottom row.

    "
    Public Sub Main()
    Dim Counter As Integer
    Dim NumOfStars As Integer
    Dim Stars As String

    Stars = "*"

    NumOfStars = InputBox("Please input number of stars on bottom row:")

    For Counter = 1 To NumOfStars
    Debug.Print Stars; ""
    Stars = Stars + "*"
    Next Counter

    End Sub
    "

    Project1b: Do the same as above except opposite way around i.e upside down triangle. answer should look something like this


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

    and this is how i tryed to answer the question even though i did it wrong

    "
    Public Sub Main()

    Dim Counter As Integer
    Dim NumOfStars As Integer
    Dim Stars As String

    NumOfStars = InputBox("Please input number of stars on top row:")
    Stars = "*"

    For Counter = NumOfStars To 1 Step -1
    Debug.Print Stars; ""
    Stars = Stars - "*"
    Next Counter

    End Sub
    "

    anyone know the answer to the project1b?
    thanks

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Here you go

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim Counter As Integer
    3. Dim NumOfStars As Integer
    4. Dim Stars As String
    5.  
    6. NumOfStars = InputBox("Please input number of stars on top row:")
    7. Stars = "*"
    8.  
    9. Do Until NumOfStars = "0"
    10. Do Until Len(Stars) = NumOfStars
    11. Stars = Stars + "*"
    12. Loop
    13. Debug.Print Stars; ""
    14. NumOfStars = NumOfStars - 1
    15. Stars = "*"
    16. Loop
    17. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    4

    Thumbs up

    cheers

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