DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 14 of 14

Thread: help please

  1. #1
    Join Date
    May 2005
    Posts
    29

    help please

    aprogram using while loops or for loops to draw a christmas atree ,such as :
    *
    ***
    *****


    * has box for the tree
    Draw at least 10 levels of the tree , increasing the size of each level. ( space between each asterisk for visbility is optional )

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    What problem are you having? Please post the code you have so far.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    Methinks I smell a student project...
    Bob Rouse
    Dimension Data

  4. #4
    Join Date
    May 2005
    Posts
    29
    this my code but will looks like the first one
    what I need is to be looks like TREE !!


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btntree.Click
    Dim i, j As Integer
    Dim raw As String
    For i = 1 To 12
    raw = " "
    For j = 1 To i
    raw &= "*"
    Next
    Lsttree.Items.Add(raw)
    Next

    End Sub

  5. #5
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    You need to add something akin to:

    raw = Space((12 - i) / 2) & raw & Space((12 - i) / 2)

    after the inner loop (the first "Next")
    Bob Rouse
    Dimension Data

  6. #6
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try this:
    Code:
    Dim i, j As Integer
    Dim raw As String
    For i = 1 To 24 Step 2
        raw = ""
        For j = 1 To i
            raw &= "*"
        Next
        raw = Space((24 - i) \ 2) & raw
        Lsttree.Items.Add(raw)
    Next
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  7. #7
    Join Date
    May 2005
    Posts
    29
    THANKSSS ALOTSSSSS .... it work
    i was trying to do it in long way but this 's easier
    HAVE AGREAT WEEKEND

  8. #8
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    The important thing, though, is do you understand why it works? ;-)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  9. #9
    Join Date
    May 2005
    Posts
    29
    yeahhhh i understood

  10. #10
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    not to sound peeky (please correct my spelling), but because this is a "learning" thread:
    The code
    Code:
       raw = ""
        For j = 1 To i
            raw &= "*"
        Next
    can be replaced with:

    raw = String(i, "*")

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  11. #11
    Join Date
    May 2005
    Posts
    29
    THankkkkkkkkkkk you agin

  12. #12
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Marco: Except that his assignment specifically said to use "while loops or for loops." ;-)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  13. #13
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    I know, but I could not resist... there is an outer loop anyway!

    To the original poster: you can change the space between asterisks printing directly in the Form via
    Me.Print "*"
    This prints an asterisk at the coordinates:
    Me.CurrentX
    Me.CurrentY
    To find the size of a string you can use:
    Me.TextWidth
    Me.TextHeight
    And remember to do your drawing in the Form_Paint event.
    That is enough for today, I think.

    Marco
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  14. #14
    Join Date
    May 2005
    Posts
    29
    lol .... thank you so much PHil and Macro.
    I learned from both of you new things

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links