[英]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.