MsgBox in VBA

  • 14 years ago
    I am trying to use a MsgBox to display a list of sixteen file names, using Chr$(13) = Chr$(10) after each file name to make a vertical list.
    The list of file names is held in a string variable <ListOfFiles>  in the form: <filename1+Chr$(13)+Chr$(10)+ filename2+Chr$(13)+Chr$(10)+... +filename16+Chr$(13)+Chr$(10)>
    However, the MsgBox only displays the first file name.
    The description of the MsgBox function states that multiple lines can be used by adding the CrLf pair, but when I use as the Propmpt" value:
    ("Files downloaded and"+Chr$(13)+Chr$(10)+"deleted from server:"+ListOfFiles)
    I get the two lines of text and the first filename only.

    The text appears as

    Files downloaded and
    deleted from server:
    filename1

    I also tried putting each filename and its associated CrLf  in one cell of an array, then appending each array cell to the above text. This gave the same result.

    Is there a limit to the number of lines of text that a MsgBox can display ?  Nothing is mentioned in the VBA Help file about this.

    Maybe I need to put the "+ Chr$(13) + Chr$(10)" separately in the "prompt" brackets, rather than including them in the variable ListOfFiles ?




















  • 14 years ago
    Update:
    Just tried my own suggestion at the bottom of the previous post.
    It gives the same result as the other methods.



  • 14 years ago
    I wasn't able to re-create your problem.  I don't see anything wrong with what you have either so I dont' know what to tell you.    I would first double check your string to make sure there aren't any problems.  Maybe even output it to a multiline textbox to see if it displays properly there.  Clearly the line breaks are working because it works for the first 3 lines.  If you still can't get it maybe you could post the code for us so we could get a better look at it.  Also try testing something very simple. For instance Msgbox("Line 1" & vbcrlf & "Line 2" & vbcrlf & "Line 3" & vbcrlf & "Line 4").  Also perhaps you could try using the constansts vbcrlf or vbnewline.  They both worked for me.
  • 14 years ago
    Oooh...I was thinking there was probably a typo.  So as a shot in the dark I tryed a few logical typos.  If you try msgbox("Line 1" & chr(13) & chr(10) & "Line 2" & chr(13) & chr(10)  & "Line 3" & chr(13) & chr(0) & "Line 4")...Notice the chr(0) just before the text "Line 4".  If you try it you'll see that "Line 4" gets cut off.  I think I found your problem.  Look for a chr(0) in your code.
  • 14 years ago
    TwoFaced, you are brilliant !
    After much searching, I found that the filename I wanted to display was held in a string which had a Chr$(0) directly after the filename and then spaces to fill up to the defined string length.
    Putting in some code to remove everything except the actual filename characters before displaying them, worked fine.
    Thank you very much.




Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry