For i = 1 To Len(str1) For j = 0 To UBound(strA) - 1 If Mid(str1, i, 2) = strA(j) Then MsgBox strA(j) & "在" & i blnJ = True Exit For End If Next j If blnJ Then Exit For Next i
End Sub
Dim intPosition As Integer Dim strData As String Dim intMinLength As Integer Dim strSource1 As String Dim strSource2 As String Dim i As IntegerstrSource1="01,02,03,08,07,05,04"'//你可以用一个循环把mshflexgrid指定列读出来,比如读第二列: '//For i = 0 To mshflexgrid1.Rows '// strSource1=strSource1 & mshflexgrid1.TextMatrix(i,1) & "," '// Next strSource2="04,05,03,08"If Ubound(Split(strSource1,","))>Ubound(Split(strSource2,",")) Then intMinLength=Ubound(Split(strSource2,",")) Else intMinLength=Ubound(Split(strSource1,",")) End IfFor i=0 To intMinLength If Split(strSource1,",")(i)=Split(strSource2,",")(i) Then intPosition=i strData=Split(strSource1,",")(i) Exit For End If Next
Option ExplicitPrivate Sub Form_Load() Dim Text As String Dim FindText As String Text = "01,02,03,08,07,05,04" FindText = "04,05,03,08"
Dim Arr() As String
Dim cArr() As Long
Arr = Split(FindText, ",")
ReDim cArr(UBound(Arr)) As Long
Dim i As Long
For i = 0 To UBound(Arr)
cArr(i) = InStr(1, Text, Arr(i)) 'MsgBox cArr(i)
Next
Dim Index As Long Dim Bak As Long Bak = cArr(0) Index = 0 For i = 0 To UBound(cArr) If Bak > CLng(cArr(i)) Then Bak = cArr(i) Index = i End If Next MsgBox Arr(Index)
Dim str1 As String
Dim str2 As String
Dim strA() As String
Dim i As Integer
Dim j As Integer
Dim blnJ As Boolean
str1 = "01,02,03,08,07,05,04"
str2 = "04,05,03,08"
strA = Split(str2, ",")
For i = 1 To Len(str1)
For j = 0 To UBound(strA) - 1
If Mid(str1, i, 2) = strA(j) Then
MsgBox strA(j) & "在" & i
blnJ = True
Exit For
End If
Next j
If blnJ Then Exit For
Next i
End Sub
Dim intPosition As Integer
Dim strData As String
Dim intMinLength As Integer
Dim strSource1 As String
Dim strSource2 As String
Dim i As IntegerstrSource1="01,02,03,08,07,05,04"'//你可以用一个循环把mshflexgrid指定列读出来,比如读第二列:
'//For i = 0 To mshflexgrid1.Rows
'// strSource1=strSource1 & mshflexgrid1.TextMatrix(i,1) & ","
'// Next
strSource2="04,05,03,08"If Ubound(Split(strSource1,","))>Ubound(Split(strSource2,",")) Then
intMinLength=Ubound(Split(strSource2,","))
Else
intMinLength=Ubound(Split(strSource1,","))
End IfFor i=0 To intMinLength
If Split(strSource1,",")(i)=Split(strSource2,",")(i) Then
intPosition=i
strData=Split(strSource1,",")(i)
Exit For
End If
Next
Dim Text As String
Dim FindText As String
Text = "01,02,03,08,07,05,04"
FindText = "04,05,03,08"
Dim Arr() As String
Dim cArr() As Long
Arr = Split(FindText, ",")
ReDim cArr(UBound(Arr)) As Long
Dim i As Long
For i = 0 To UBound(Arr)
cArr(i) = InStr(1, Text, Arr(i))
'MsgBox cArr(i)
Next
Dim Index As Long
Dim Bak As Long
Bak = cArr(0)
Index = 0
For i = 0 To UBound(cArr)
If Bak > CLng(cArr(i)) Then
Bak = cArr(i)
Index = i
End If
Next MsgBox Arr(Index)
End Sub