我有一個主要工作,除了我有一個驗證錯誤... 我的代碼已經在那裏我把姓搜索框代碼,這個想法是,如果輸入的姓是在Excel表格和一堆信息被返回。這可以按需要工作,我的驗證也不會在搜索框中輸入任何數據。VB從Excel中獲取數據 - 驗證
什麼不工作是我的,當我在搜索框中這是不匹配輸入驗證的東西(即不是在Excel工作表)。請參閱以下代碼中的「匹配驗證」以查看我所指的內容。
我只是不知道爲什麼它不工作。我當我運行的代碼和錯誤數據輸入甚至沒有得到一個錯誤,它只是不返回錯誤消息像它應該和表格排序凍結了(有點像其在非停循環)。
任何意見將是巨大的,謝謝!這裏是一些代碼:
'define objects
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object
'Open a existing workbook and sheet in excel
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Open(Filename:="c:\users\timothy\desktop\coding\output.xlsx")
oSheet = oBook.Worksheets(1)
Dim getSurname As String = ""
Dim getFirstname As String = ""
Dim getAge As String = ""
Dim getGender As String = ""
Dim getNum As Integer = 1
Dim getValidate As Integer = 0
While oBook.Worksheets(1).Range("A" & getNum).value <> searchInput.Text.ToUpper
getNum = getNum + 1
End While
'Length Validation (THIS WORKS)
If Len(searchInput.Text) = 0 Then
getValidate = getValidate + 1
End If
'Match validation (THIS DOES NOT WORK)
If oBook.Worksheets(1).Range("A" & getNum).value <> searchInput.Text.ToUpper Then
getValidate = getValidate + 1
End If
If getValidate = 0 Then
getSurname = oSheet.Range("A" & getNum).Value.ToString
getFirstname = oSheet.Range("B" & getNum).Value.ToString
getAge = oSheet.Range("C" & getNum).Value.ToString
getGender = oSheet.Range("D" & getNum).Value.ToString
outputData.Text = "SURNAME: " & getSurname & vbCrLf & "FIRSTNAME: " & getFirstname & vbCrLf & "AGE: " & getAge & vbCrLf & "GENDER: " & getGender & vbCrLf
Else
MsgBox("ERROR!! Please enter valid Quote Number.")
End If
是VBA或vb.net? –
嗨,這是VB .... – user3498380