JayBeeOH

Tree (Console App.)

Jun 9th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.74 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2015. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   Tree
  13. '
  14. ' Author:         Joseph L. Bolen
  15. ' Date Created:   June 2015
  16. '
  17. ' Description:    Simple console app making a tree.
  18. '
  19. '                 Documentation is at:
  20. '                   App's Visual Basic .NET code is at http://pastebin.com/u/jaybeeoh
  21. '                   Video tutorials at YouTube: http://www.youtube.com/user/bolenpresents
  22. '-------------------------------------------------------------------------------------------
  23. Module Tree
  24.  
  25.     Dim limbs As Integer
  26.  
  27.     Sub Main()
  28.  
  29.         Console.Clear()
  30.  
  31.         Do
  32.             Console.Write("How many limbs for your tree? Enter 1-15 or press Enter to end program: ")
  33.             Dim text As String = Console.ReadLine()
  34.             If text.Trim = String.Empty Then Exit Do
  35.             If Integer.TryParse(text, limbs) Then
  36.                 If limbs > 0 AndAlso limbs < 16 Then
  37.                     MakeTree()
  38.                 Else
  39.                     Console.WriteLine("Please enter a number value between 1 and 15. Please reenter.")
  40.                 End If
  41.             Else
  42.                 Console.WriteLine("Please enter a number value. Please reenter.")
  43.             End If
  44.         Loop
  45.     End Sub
  46.  
  47.     Sub MakeTree()
  48.         Dim ctr As Integer = 40
  49.  
  50.         Console.Clear()
  51.         Console.WriteLine()
  52.         Console.WriteLine(Space(ctr) & "I")
  53.         For idx As Integer = 1 To limbs
  54.             Console.WriteLine(Space(ctr - idx) & StrDup(idx, "*") & "I" & StrDup(idx, "*"))
  55.         Next
  56.         ' Adjust trunk size and height to be proportional to the number of limbs.
  57.         Dim trunk As Integer = Convert.ToInt32(limbs * 0.2)
  58.         Dim trunkHeight As Integer = trunk
  59.         If trunkHeight < 1 Then
  60.             Console.WriteLine(Space(ctr) & "I")
  61.         Else
  62.             For idx = 1 To trunk
  63.                 Console.WriteLine(Space(ctr - trunk) & StrDup(trunk, "*") & "I" & StrDup(trunk, "*"))
  64.             Next
  65.         End If
  66.         Console.WriteLine()
  67.         Console.WriteLine()
  68.     End Sub
  69. End Module
Advertisement
Add Comment
Please, Sign In to add comment