[英]VB.NET: Check if input in textbox is in string array
Private Sub txtQty_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtQty.GotFocus
Dim strItem As String
strItem = txtItem.Text
Dim strArray As String
strArray = itemArr(1)
If String.Compare(strItem, strArray) = True Then
MessageBox.Show("item in array!")
End If
End Sub
Private Sub txtQty_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtQty.TextChanged
If txtItem.Text <> Nothing And txtQty.Text <> Nothing Then
'create rows in the DataTable
tblScItem.Rows.Add(itemArray())
End If
txtItem.Text = ""
txtQty.Text = ""
End Sub
這就是我聲明數組的方式:
Function itemArray() As String()
itemArr(0) = ""
itemArr(1) = txtItem.Text
itemArr(2) = Form2.cbGondola.SelectedItem
itemArr(3) = txtQty.Text
itemArr(4) = DateTime.Now
itemArr(5) = Form1.txtLoginId.Text
Return itemArr
End Function
我似乎沒有做適當的檢查,幫助!
String.Compare
方法不返回布爾值,而是返回整數。
如果字符串相等,則返回0
。
If String.Compare(strItem, strArray) = 0 Then
您應該在項目中將Option Strict
設置為On
,以便編譯器不允許從布爾值到整數的隱式轉換。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.