这样行不行?
根据条件 text2 查找对应的内容
dim i as integer
for i=0 to ubound(split(text1.text,vbcrlf))
if split(split(text1.text,vbcrlf)(i)," ")(0)=text2.text then
msgbox split(split(text1.text,vbcrlf)(i)," ")(1),,"查询成功"
exit sub
end if
next
msgbox "找不到数据!",,"查询失败"
追问能有办法同时采集A1 A2 存在不同的变量里面吗?
追答可以 等我换电脑 打
追问需要转换最新的A1和A2 谢谢
追答Dim A1() As String
Dim A2() As String
Dim i As Integer
ReDim A1(0)
ReDim A2(0)
For i = 0 To UBound(Split(Text1.Text, vbCrLf)) - 1
If Split(Split(Text1.Text, vbCrLf)(i), " ")(0) = "A1" Then
If A1(0) <> "" Then ReDim Preserve A1(UBound(A1) + 1)
A1(UBound(A1)) = Split(Split(Text1.Text, vbCrLf)(i), " ")(1)
ElseIf Split(Split(Text1.Text, vbCrLf)(i), " ")(0) = "A2" Then
If A2(0) <> "" Then ReDim Preserve A2(UBound(A2) + 1)
A1(UBound(A1)) = Split(Split(Text1.Text, vbCrLf)(i), " ")(1)
End If
Next
追问能不能帮我把A1的放在TEXE3,A2的放在TEXT3
追答'如果只需放在 TEXT2 和 TEXT3的话,就不需要用到数组了
Dim i As Integer
text2.text=""
text3.text=""
For i = 0 To UBound(Split(Text1.Text, vbCrLf)) - 1
If Split(Split(Text1.Text, vbCrLf)(i), " ")(0) = "A1" Then
text2.text =text2.text & Split(Split(Text1.Text, vbCrLf)(i), " ")(1) & vbCrlf
ElseIf Split(Split(Text1.Text, vbCrLf)(i), " ")(0) = "A2" Then
text3.text =text3.text & Split(Split(Text1.Text, vbCrLf)(i), " ")(1) & vbCrlf
End If
Next
追问这个运行以后 A2会采两次 A1不是最新的只需最新的
追答就是说 只需要输出 最后一次出现 a1 和 a2 时 的数据 是吗?
追问是的 他的数据一直在往 电脑传 A1 A2 的顺序不一定
追答Dim i As Integer
text2.text=""
text3.text=""
For i = 0 To UBound(Split(Text1.Text, vbCrLf))
If Split(Split(Text1.Text, vbCrLf)(i), " ")(0) = "A1" Then
text2.text =Split(Split(Text1.Text, vbCrLf)(i), " ")(1) & vbCrlf
ElseIf Split(Split(Text1.Text, vbCrLf)(i), " ")(0) = "A2" Then
text3.text =Split(Split(Text1.Text, vbCrLf)(i), " ")(1) & vbCrlf
End If
Next
'如果 A1 和 A2 的格式固定为 Ax + 1个空格 + 长度为四的任意字符串 也可以这么写
text2.text =Mid(Text1, InStrRev(Text1.Text, "A1") + 3, 4)
text2.text= Mid(Text1, InStrRev(Text1.Text, "A2") + 3, 4)