0
我有一個網頁表單,它可能會或可能不會在提交時產生空白答案。爲了彌補這一點,我寫了一個for循環來設置每個變量爲空的字符串「(空白)。但是for循環不返回任何內容。 我的輸出發生了什麼?我是否正確使用」Is Nothing「?我的輸出發生了什麼? (我是否正確使用「沒什麼」?)
Imports System.Data.OleDb
Imports System.Net.Mail
Imports System.Text
Partial Class acen_EarlyIntervention
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Insert Form Values into an array
Dim strDate As String = "Date: " & Dates.Text
Dim strStudent As String = "Student: " & Student.Text
Dim strUin As String = "UIN: " & UIN.Text
Dim strSContact As String = "Student Contact: " & SContact.Text()
Dim strCourse As String = "Course: " & Course.Text
Dim strFaculty As String = "Refering Facilty: " & Refer.Text
Dim strFContact As String = "Faculty Contact: " & FContact.Text
Dim strReason As String = "Reasons:" & Reason.Text
Dim strPContact As String = "Previous Contact: " & Before.Text
Dim strMContact As String = "Mthod of Contact: " & DropDownList1.Text
Dim strOMC As String = "Other Method of Contact: " & TextBox8.Text
Dim strComment As String = "Additional Comments: " & TextBox9.Text
'Creating email string
Dim sBodyBuilder As New StringBuilder
Dim values As String() = {strDate, strStudent, strUin, strSContact, strCourse, strFaculty, strFContact, strReason, strPContact, strMContact, strOMC, strComment}
For Each item In values
If item Is Nothing Then
item = "(blank)"
sBodyBuilder.AppendLine(item)
End If
Next item
Dim body As String = sBodyBuilder.ToString
如上所述,在使用提示字符串初始化每個變量時,永遠不會是'Nothing',並且您已經擁有了表單變量不需要將它們重新分配給局部變量 – fnostro