【发布时间】:2020-06-23 06:28:35
【问题描述】:
我有一个这样的数组:
jack,33500;luci,36120;andro,33941;jenifer,25980;ivanka,12500
我想在我的文本框中写 33941 时找到例如 "andro"。
注意 em>:我发现很多其他编程方法的代码,但我需要获取在MS Access中使用的代码。
我的代码如下所示。 当我单击列表框时,我的数组已构建,同时我希望显示结果,但它显然会返回错误(子字符串超出范围) 代码:
Private Sub txNumber1_Click()
Dim CurMobile As String, curMesssage As String, strMobiles As String, strMesssages As String, strMM As String
Dim rowNum As Variant
Dim TestArrayMobile() As String
Dim TestArrayMessage() As String
Dim arr() As String
Dim i As Integer
Dim j As Integer
' Get selected phone numbers & names
With txNumber1
For Each rowNum In .ItemsSelected
CurMobile = .Column(1, rowNum)
curMesssage = .Column(3, rowNum)
strMM = strMM + ";" + curMesssage + "," + CurMobile
arr() = Split(strMM, ";")
For j = LBound(arr) To UBound(arr)
' MsgBox arr(j, 1), , arr(j, 0)
MsgBox arr(j, 1)
' If StrComp(.Column(1, rowNum), arr(j, 1), vbTextCompare) = 0 Then
' MsgBox arr(j, 0)
' Exit For
' End If
Next j
Next rowNum
End With
End Sub
【问题讨论】:
-
为什么是数组?没有包含此信息的表格吗?如果您想“搜索”一组虚拟数据,可能应该使用集合对象而不是数组。使用数组,必须循环遍历数组元素,直到遇到匹配。
-
ma 数据通过 Web 服务以上述数组的形式返回,我需要将其中一个数字分开并从表中保存名称和其他内容并将它们插入到表中
-
数据是作为数组接收还是只是一个字符串?您显示的内容看起来像一个字符串。
-
嗨,我把我的代码放在上面了。