這是一段寫在CheckFieldData裡面的Sample code
<pre class="c" name="code">
'*********************************************************************
'程序名稱: CheckFieldData()
' 表單傳送前欄位檢查函數
'
'程序說明: 您可以在這裡寫下表單傳送前欄位檢查的程式碼。
' 成功時 sysCheckFieldData 欄位傳回 True,失敗傳回 False
'*********************************************************************
Dim aryData, nItem
If Grid_Detail.Rows <> 0 Then
For nItem = 0 To Grid_Detail.Rows - 1
aryData = Grid_Detail.GetRowByVBArray(nItem)
If Trim(aryData(0)) = "" Then
strErr = strErr & "[產品敘述]不可空白。" & vbCrLf
blnError = True
Exit For
End If
'If Trim(aryData(1)) = "" Then
' strErr = strErr & "[品名]不可空白。" & vbCrLf
' blnError = True
' Exit For
'End If
'If Trim(aryData(2)) = "" Then
' strErr = strErr & "[供應商]不可空白。" & vbCrLf
' blnError = True
' Exit For
'End If
If Trim(aryData(4)) = "" Then
strErr = strErr & "[採購數量]不可空白。" & vbCrLf
blnError = True
Exit For
End If
If Not IsNumeric(aryData(4)) Then
strErr = strErr & "[採購數量]必須為數值。" & vbCrLf
blnError = True
Exit For
End If
If CLng(aryData(4)) < 0 Then
strErr = strErr & "[採購數量]不可小於零。" & vbCrLf
blnError = True
Exit For
End If
'If Trim(aryData(5)) = "" Then
' strErr = strErr & "[單位]不可空白。" & vbCrLf
' blnError = True
' Exit For
'End If
If Trim(aryData(6)) = "" Then
strErr = strErr & "[採購單價]不可空白。" & vbCrLf
blnError = True
Exit For
End If
If Not IsNumeric(aryData(6)) Then
strErr = strErr & "[採購單價]必須為數值。" & vbCrLf
blnError = True
Exit For
End If
If CDbl(aryData(6)) <= 0 Then
strErr = strErr & "[採購單價]不可等於零。" & vbCrLf
blnError = True
Exit For
End If
If Trim(aryData(7)) = "" Then
strErr = strErr & "[採購金額]不可空白。" & vbCrLf
blnError = True
Exit For
End If
If Not IsNumeric(aryData(7)) Then
strErr = strErr & "[採購金額]必須為數值。" & vbCrLf
blnError = True
Exit For
End If
If CLng(aryData(7)) <= 0 Then
strErr = strErr & "[採購金額]不可等於零。" & vbCrLf
blnError = True
Exit For
End If
'If Trim(aryData(8)) = "" Then
' strErr = strErr & "[預交日期]不可空白。" & vbCrLf
' blnError = True
' Exit For
'End If
'If Not IsDate(aryData(8)) Then
' strErr = strErr & "[預交日期]必須為日期。" & vbCrLf
' blnError = True
' Exit For
'End If
If Trim(aryData(9)) = "" Then
strErr = strErr & "[採購碼]不可空白。" & vbCrLf
blnError = True
Exit For
End If
If Trim(aryData(10)) = "" Then
strErr = strErr & "[結案碼]不可空白。" & vbCrLf
blnError = True
Exit For
End If
Next
Else
strErr = strErr & "明細表至少要有一筆資料。" & vbCrLf
blnError = True
End If