Results 1 to 4 of 4

Thread: [RESOLVED] Help needed with console app

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    10

    Resolved [RESOLVED] Help needed with console app

    I just need to know an easy way to wrap the text in my console application I have 5 lines of text I was displayed like a nice clean paragraph no matter the size of the window.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help needed with console app

    The Console.WindowWidth property will tell you how many characters wide the window is, so you can break your text up into substrings of that length.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2007
    Posts
    10

    Re: [RESOLVED] Help needed with console app

    Thanks for the reply but I ended up just taking a shorter route so it all worked out. I'm still a newbie =P I'm only on my 8th week of class on vb.net and I'm a first time programmer and we havn't covered console.windowwidth yet so I don't really know what to do with it but thanks anyways.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Help needed with console app

    vb.net Code:
    1. Private Sub WriteWithWrap(ByVal text As String)
    2.     Dim maxCharCount As Integer = Console.WindowWidth
    3.  
    4.     Do
    5.         If text.Length > maxCharCount Then
    6.             'Write the first line of text.
    7.             Console.WriteLine(text.Substring(0, maxCharCount))
    8.  
    9.             'Remove the characters that have already been written.
    10.             text = text.Substring(maxCharCount)
    11.         Else
    12.             'Write the entire text and exit the loop.
    13.             Console.WriteLine(text)
    14.             Exit Do
    15.         End If
    16.     Loop
    17. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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