0

我想在一个 MsgBox 中包含多条消息,使用\n. 当显示 MsgBox 时,我需要删除此字符串。

这是我的代码。

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)
4

2 回答 2

2

StringBuilder当您需要动态构建字符串时,通常是一个不错的选择。它通常性能更好,并且通常比执行一堆字符串连接更清洁、更易于维护的代码。

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

但是,正如 Matt Wilko 指出的那样,如果这是 ASP.NET,那么您根本不想使用 MsgBox。

于 2013-06-13T13:04:30.300 回答
1

像这样 ...

Msg = "Please enter First Name!" & vbCrlf
Msg &= "Please enter Last Name!" & vbCrlf
Msg &= "Please Select department"
于 2013-06-13T07:47:03.710 回答