0

I want to include multiple messages in one MsgBox using \n. I need to remove this string when the MsgBox is shown.

This is my code.

Dim Msg As String = ""
Dim EmployeeFirstName As String
Dim EmployeeLastName As String
EmployeeFirstName = txtFirstName.Text.Trim
EmployeeLastName = txtLastName.Text.Trim
If EmployeeFirstName = "" Then
  Msg = "Please enter First Name!"
  Msg += "/n"
End If
If EmployeeLastName = "" Then
  Msg += "Please enter Last Name!"
  Msg += "/n"
End If
If ddlGender.SelectedItem.Value = -1 Then
  Msg += "Plrase Select department"
  Msg += "/n"
End If
MsgBox(Msg)
2
  • Note that you should avoid using MsgBox in asp.net. You may find this doesn't work when you deploy your application as the MsgBox only runs Server side. Have a look at this instead : stackoverflow.com/questions/8338630/messagebox-in-asp-net Commented Jun 13, 2013 at 9:06
  • What string do you need to remove? It's worth noting that you say \n in your question and then post code that includes /n, but in VB you typically need to use the constant vbCrLf anyway. Commented Jun 13, 2013 at 13:07

2 Answers 2

2

StringBuilder is usually a good choice when you need to build a string dynamically. It often performs better, and generally makes for cleaner, more maintainable code than doing a bunch of string concatenation.

Dim msgBuilder As New StringBuilder()
'...
If EmployeeFirstName = "" Then
    msgBuilder.AppendLine("Please enter First Name!")
End If
'And so forth
MsgBox(msgBuilder.ToString())

But, as Matt Wilko points out, if this is ASP.NET, you don't want to use MsgBox at all.

Sign up to request clarification or add additional context in comments.

Comments

1

Like this ...

Msg = "Please enter First Name!" & vbCrlf
Msg &= "Please enter Last Name!" & vbCrlf
Msg &= "Please Select department"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.