Results 1 to 20 of 20

Thread: [RESOLVED] Message box with two lines

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    26

    Resolved [RESOLVED] Message box with two lines

    Hi there
    I need one message box with two lines. How can i do that?
    Thank you

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Message box with two lines

    Moved From The CodeBank

  3. #3

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Message box with two lines

    Code:
            MessageBox.Show("This" & Environment.NewLine & "is" & Environment.NewLine & "a test", "Lines", MessageBoxButtons.YesNoCancel)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Message box with two lines

    Hi,

    This is another way to do it;

    vb Code:
    1. MessageBox.Show("This is your fist line," & vbNewLine & "this your second line.")

    This is also working like the others but what's the difference between all three!

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Message box with two lines

    Quote Originally Posted by sparrow1
    Hi,

    This is another way to do it;

    vb Code:
    1. MessageBox.Show("This is your fist line," & vbNewLine & "this your second line.")

    This is also working like the others but what's the difference between all three!

    Wkr,

    sparrow1
    http://msdn.microsoft.com/en-us/libr...h0(VS.80).aspx
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  7. #7
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Message box with two lines

    Quote Originally Posted by JuggaloBrotha
    Is vbNewLine the same as vbCrLf? I always use the latter. According to that link they are both Chr(13)+Chr(10). Just wondering why there are two constants for the same thing...

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Message box with two lines

    see remarks here

    http://msdn.microsoft.com/en-us/libr...t.newline.aspx

    for why i use Environment.NewLine
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Message box with two lines

    Quote Originally Posted by nbrege
    Is vbNewLine the same as vbCrLf? I always use the latter. According to that link they are both Chr(13)+Chr(10). Just wondering why there are two constants for the same thing...
    Don't use either, use Environment.NewLine instead.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  10. #10
    Junior Member
    Join Date
    Sep 2008
    Location
    United Kingdom
    Posts
    18

    Re: Message box with two lines

    Juggalo ... why ?

    I have always used vbCrLF (chr(13) + chr(10)) so I am just wondering what the percieved advantage of Environment.NewLine is, from what I can tell with the following code

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim lString As String = ""
            For Each l As Char In Environment.NewLine
                lString += "," & Asc(l)
            Next
            MsgBox(lString)
        End Sub
    Environment.Newline just returns chrs 13 and 10 (although this may change on other machines I suppose)

  11. #11
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Message box with two lines

    Quote Originally Posted by SpaceMonkeys
    Juggalo ... why ?
    The environment class is there to allow you to use things based on the environment (the OS) that your app is running on. For instance, ControlChars.NewLine, vbNewLine, vbCrLf, vbLf should all fail in your .Net applications when it's running on Mono (Linux/Mac) because all you need is the Cr (Carrage Return) and not the Lf (Line Feed) for a new line, whereas in windows it uses both Cr and Lf for a new line. So on Windows Environment.NewLine gives you the CrLf combination whereas the same Environment.NewLine on Mono gives you just the Cr.

    In short, Environment.NewLine reduces the need to check for what OS your app is running on because that's already defined in the Environment class.

    And a quote from MSDN:
    Property Value
    Type: System.String

    A string containing "\r\n" for non-Unix platforms,

    or

    a string containing "\n" for Unix platforms.
    http://msdn.microsoft.com/en-us/libr...t.newline.aspx
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  12. #12
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Message box with two lines

    Juggalo ... makes perfect sense. But if we only develope Windows apps then it shouldn't make a difference one way or the other, right?

  13. #13
    Junior Member
    Join Date
    Sep 2008
    Location
    United Kingdom
    Posts
    18

    Re: Message box with two lines

    Cool, that's what I though you were going to say (coming from a C++ background) just wanted to be sure, if your going to be developing windows only apps yeah either will be fine .... but good practice is good practice

  14. #14
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Message box with two lines

    Quote Originally Posted by nbrege
    Juggalo ... makes perfect sense. But if we only develope Windows apps then it shouldn't make a difference one way or the other, right?
    Yes, but what if you're suddenly told by your boss that your app is going to be modified to run on Mono as well as Windows and tells you to make the changes by the end of the week, would you want to spend a day or more changing all of the vbCrLf's and vbNewLine's and ControlChar.Newline's to Environment.NewLine?

    I wouldn't.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  15. #15
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Message box with two lines

    I personally have a shared routine that I include in every app I work on called NL

    It looks like this:

    Code:
        Public Shared Function NL(Optional ByVal Count As Integer = 1) As String
            'HOLDS OUR NEWLINES
            Dim temp As String = String.Empty
            'IF USER PASSED IN NEGATIVE OR 0, MAKE 1
            If Count < 1 Then Count = 1
            'LOOP TO MAKE AS MANY NEW LINES AS WE WANT
            For i As Integer = 1 To Count
                temp &= Environment.NewLine
            Next
            'RETURN VALUE
            Return temp
        End Function
    It is usually sitting in a module in a linked file to my project so it is easy to reuse. You could also put it in a class and reference it as a DLL though with other support functions you may make and use frequently in many projects.


    Anyway, the reason I made a function, is because then when I want a newline all I have to type is NL
    Code:
    Dim x as string = "Hello" & NL & "World"
    'Result:
    'Hello
    'World
    But if I want 2 blank lines, I can also do
    Code:
    Dim x as string = "Hello" & NL(2) & "World"
    'Result:
    'Hello
    '
    'World
    etc....

    Since the param is optional, it defaults to 1 line when you don't pass an argument. It also would make this very easy to change if I decided for some reason I did want to use vbCrLf or something like that instead of Environment.NewLine (or maybe I want to change to use a stringbuilder object instead of a temp string variable to build my newlines). If I ever did want to change the functionality, I could just change it in the function, and not have to update it in 50 million spots in my app.

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Message box with two lines

    oh, and just one additional comment. I noticed when I had formatted some messages for a messagebox to be multiline, and it looked fine on XP, I noticed the same messagebox would actually have line breaks in different spots on Vista.

    I guess they changed the text area of messageboxes in vista, with relation to the width a messagebox will get to based on its text before it forces a newline. So if you format your messageboxes with newlines to look all nice in 1 OS, it may look like crap in another, so make sure to test.

  17. #17
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Message box with two lines

    Quote Originally Posted by kleinma
    Code:
        Public Shared Function NL(Optional ByVal Count As Integer = 1) As String
            ...snip
            For i As Integer = 1 To Count
                temp &= Environment.NewLine
            Next
            ...snip

    Instead of a loop you could use this:

    Code:
    temp = StrDup(Count, Environment.NewLine)
    It might be a little more efficient. Or maybe not. Nice routine BTW...
    Last edited by nbrege; Sep 30th, 2008 at 03:01 PM.

  18. #18
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Message box with two lines

    StrDup duplicates the first character in a string, so I have not tested, as I don't use it, but environment.newline is a cr and lf as stated above for Windows machines, so there is a good change using StrDup would return ONLY a string of CR characters, and no LF characters.

    From Help:
    StrDup
    This function returns a String made up of repeated characters. The character that makes up the string is the first character in the Character argument, and it is duplicated Number number of times.

    Code:
    Dim aString As String = "Wow! What a string!"
    ' Returns "WWWWWWWWWW"
    TestString = StrDup(10, aString)

  19. #19
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Message box with two lines

    Oops .. my bad. I should have tested before posting.

  20. #20
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Message box with two lines

    Hi All,

    Thanks for the explanations, I'll use it in the future.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

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