Reputation: 24539
I am trying to print a 'last receipt' from a customer in which i have stored into a sting variable called prevRecpt.
I want to be able to press a button (btnLastReceipt) and this will display this sting in a message box.
Is this possible? As I have already tried and ended up with the message box only showing the first line?
prevRcpt = "--------------------Butlers Cinemas--------------------" & Environment.NewLine
prevRcpt = prevRcpt & tbTime.Text & Environment.NewLine
prevRcpt = prevRcpt + "Operator: " + tbUser.Text & Environment.NewLine
prevRcpt = prevRcpt + Environment.NewLine & Environment.NewLine + "-------------------------------------------------------"
prevRcpt = prevRcpt + "Total Spent: £" + tbTotal.Text + Environment.NewLine + Environment.NewLine
prevRcpt = prevRcpt + shoppingCart.Text + Environment.NewLine
prevRcpt = "--------------------Butlers Cinemas--------------------" & Environment.NewLine
This is the code for building up the string.
Upvotes: 3
Views: 1926
Reputation: 10478
Have you tried concatenating Environment.NewLine
anywhere in your string?
Now that I can see your code, it seems that your last line should be this instead:
prevRcpt = prevRcpt & "--------------------Butlers Cinemas--------------------" & Environment.NewLine
That being said, you need to be aware than in the event of a very long string, the message box could size out of screen bounds, so you may want to use something else than MessageBox
. If possible, make your own dialog form, make its default size convenient for most scenarios and use a scrollable text zone within it. A readonly TextBox
with Multiline
property set to True
would not only be scrollable, but also allow the end user to copy the content in the clipboard. It may make the user's experience a lot better.
I should also mention that StringBuilder
class and a few constants could help you make this code a lot cleaner:
Const headerOrFooter As String = "--------------------Butlers Cinemas--------------------"
Const separator As String = "-------------------------------------------------------"
Dim b As New Text.StringBuilder()
b.AppendLine(headerOrFooter)
b.AppendLine(tbTime.Text)
b.AppendFormat("Operator: {0}", tbUser.Text)
b.AppendLine()
b.AppendLine()
b.AppendLine()
b.AppendLine(separator)
b.AppendFormat("Total Spent: £{0}", tbTotal.Text)
b.AppendLine()
b.AppendLine(shoppingCart.Text)
b.AppendLine(headerOrFooter)
prevRcpt = b.ToString()
Upvotes: 6