7,789
社区成员
发帖
与我相关
我的任务
分享'Combo1和Combo2的Sorted属性都设置为True
Private Sub Command1_Click()
Dim str1 As String: str1 = "A,C,D"
Dim str2 As String: str2 = "C,D,A"
Dim arr1() As String: arr1 = Split(str1, ",")
Dim arr2() As String: arr2 = Split(str2, ",")
Dim i As Long, str11 As String, str22 As String
If UBound(arr1) <> UBound(arr2) Then
MsgBox "0"
Exit Sub
Else
For i = 0 To UBound(arr1)
Combo1.AddItem arr1(i)
Combo2.AddItem arr2(i)
Next
For i = 0 To Combo1.ListCount - 1
str11 = str11 & "," & Combo1.List(i)
str22 = str22 & "," & Combo2.List(i)
Next
If str11 = str22 Then
MsgBox "1"
Else
MsgBox "0"
End If
End If
End SubOption Explicit
Public Function compStr(ByVal vStr1 As String, ByVal vStr2 As String) As Integer
Dim vArr1() As String
Dim vArr2() As String
Dim i As Integer
Dim j As Integer
Dim IsComp As Boolean
Let vArr1 = Split(vStr1, ",")
Let vArr2 = Split(vStr2, ",")
If UBound(vArr1) <> UBound(vArr2) Then
compStr = 0
Exit Function
End If
For i = 0 To UBound(vArr1)
IsComp = False
For j = 0 To UBound(vArr2)
If vArr2(j) = vArr1(i) Then
IsComp = True
compStr = 1
Exit For
End If
Next
If Not IsComp Then
compStr = 0
Exit For
End If
Next
End Function
Private Sub Command1_Click()
Dim b As Integer
b = compStr(Text1.Text, Text2.Text)
MsgBox b
End Sub
Private Sub Command1_Click()
Dim str1 As String
Dim str2 As String
Dim strArray() As String
Dim i As Integer
Dim bTheSame As Boolean
bTheSame = False
str1 = "A,C,D,D"
str2 = "C,A,D,C"
If Len(str1) <> Len(str2) Then
MsgBox "False"
Exit Sub
End If
strArray = Split(str1, ",")
str2 = "," & str2 & ","
For i = 0 To UBound(strArray)
If InStr(str2, "," & strArray(i) & ",") > 0 Then
str2 = Replace(str2, "," & strArray(i), "")
strArray(i) = ""
Else
bTheSame = False
Exit For
End If
Next i
str2 = Replace(str2, ",", "")
If Len(str2) > 0 Then
bTheSame = False
Else
If Len(Replace(Join(strArray), " ", "")) > 0 Then
bTheSame = False
Else
bTheSame = True
End If
End If
MsgBox bTheSame
End Sub
Private Sub Command1_Click()
Dim str1 As String
Dim str2 As String
str1 = "A,C,D"
str2 = "C,D"
MsgBox str_compare(str1, str2)
End Sub
Private Function str_compare(ByVal str1 As String, ByVal str2 As String) As Integer
Dim a1() As String
Dim a2() As String
a1 = Split(str1, ",")
a2 = Split(str2, ",")
If UBound(a1) <> UBound(a2) Then
str_compare = 0
Else
For i = 0 To UBound(a1)
If Not InStr(str2, a1(i)) > 0 Then
str_compare = 0
Exit For
End If
Next i
str_compare = 1
End If
End Function