系統(tǒng):Windows 10
今日歌曲: Part 1:邏輯過程
Part 2:代碼Function funAMinusB(array1, array2)
Rem>>求數(shù)組1和數(shù)組2的差集
Rem>>
Dim arrayInter
Dim array3()
Dim lenA
Dim i
Dim val1
Dim pos
Dim maxNum
Dim FlagError
lenA = 0
On Error Resume Next
Err.Clear
arrayInter = funIntersection(array1, array2)
'判斷數(shù)組是否為空
FlagError = UBound(arrayInter)
If Err.Number <> 0 Then '判斷是否為空數(shù)組
funAMinusB = array1
Else
maxNum = UBound(array1)
For i = 0 To maxNum Step 1
val1 = array1(i)
pos = Application.Match(val1, arrayInter, 0)
If IsError(pos) Then '未找到
ReDim Preserve array3(lenA)
array3(lenA) = val1
lenA = lenA 1
End If
Next i
funAMinusB = array3
End If
End Function Part 3:調(diào)用該函數(shù) array1 = Array('張三', '李四', 1, 2, 3, 4, 5)
array2 = Array(7)
array1_2 = funAMinusB(array1, array2) 執(zhí)行結(jié)果 以上為本次的學習內(nèi)容,,下回見
|
|
來自: 今天George > 《Excel VBA》