7,763
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Sub Command1_Click()
Dim Str1 As String, Str2 As String
Dim S1() As String, S2() As String, S3() As String
Dim S As String
Dim i As Integer, j As Integer, m As Integer, n As Integer
Str1 = "9 1 10 6 13"
Str2 = "9 10 11 12 13"
S1 = Split(Str1, " "): S2 = Split(Str2, " ")
m = 0: n = 0
For i = 0 To UBound(S1)
For j = 0 To UBound(S2)
If Val(S1(i)) = Val(S2(j)) Then
m = m + 1: S = S & (S1(i) & " ")
Debug.Print "相同的数是:" & S1(i)
End If
Next
Next
n = UBound(S2) + 1 - m
S3 = Split(S, " ")
For i = 0 To UBound(S2)
For j = 0 To UBound(S3)
If Val(S2(i)) = Val(S3(j)) Then
S2(i) = ""
End If
Next
If Len(S2(i)) <> 0 Then Debug.Print "不相同的数是:" & S2(i)
Next
Debug.Print "共有" & m & "个相同的数!", "共有" & n & "个不相同的数!"
End Sub
Private Sub Form_Load()
S1 = "9 1 10 6 13"
S2 = "9 10 11 12 13"
A = Split(S1, " ")
B = Split(S2, " ")
For i = 0 To UBound(A)
For J = 0 To UBound(A)
If A(i) = B(J) Then
k = k + 1
Debug.Print A(i)
End If
Next
Next
Debug.Print "有" & k & "个数相同"
End Sub
a = "9 1 10 6 13"
b = "9 10 11 12 13"
arr_a = split(a," ")
arr_b = split(b," ")
for i=lbound(arr_a) to ubound(arr_a)
For j=LBound(arr_b) To UBound(arr_b)
If arr_a(i) = arr_b(j) Then
Call MsgBox(arr_a(i))
End If
Next
Next
a = "9 1 10 6 13"
b = "9 10 11 12 13"
arr_a = split(a," ")
arr_b = split(b," ")
set dict = createobject("scripting.dictionary")
for i=lbound(arr_b) to ubound(arr_b)
call dict.add(arr_b(i),null)
next
for i=lbound(arr_a) to ubound(arr_a)
if dict.exists(arr_a(i)) then
call msgbox(arr_a(i))
end if
next