2013-06-13 60 views
0

我想在一個MsgBox中使用\n包含多條消息。我需要在顯示MsgBox時刪除此字符串。如何在一個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) 
+0

請注意,您應該避免在asp.net中使用MsgBox。當您部署應用程序時,您可能會發現這不起作用,因爲MsgBox僅運行服務器端。看看這個,而不是:http://stackoverflow.com/questions/8338630/messagebox-in-asp-net –

+0

你需要刪除什麼字符串?值得注意的是,你在你的問題中提及'\ n',然後發佈包含'/ n'的代碼,但是在VB中,你通常需要使用常量'vbCrLf'。 –

回答

1

就像這個...

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

thnx很多,其工作:) –

+0

@MoSmadi:你可以投票這個答案.. – matzone

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。

相關問題