今天上午因为工作的需要,必须要是实现判断数组里面是否有相同的值,有则不输出,否则输出。
由于我想可能以后在工作中还会遇到这样的情况,所以写了个函数,实现简单的功能。本人水平有限,望大家指个不足的地方。
'*****************************************
'功能: 判断数组里是否有相同的值
' label为数组里分隔的符号
' 如数组为 a,b,c,d 则label 为","
' 如数组为 a|b|c|d 则label 为"|"
' 如果有相同的值则返回 0 否则返回 1
'作者:Poon
'创建日期:2006.5.24
'修改日期:2006.5.24
'*****************************************
Function IsSameValue(byVal str,byVal sValue,byVal label)
On Error Resume Next
Dim errMsg
errMsg = "SYSTEM ERROR"
If Not (IsNull(str) OR str = "") Then
Dim splitStr, i
If IsNull(label) Then
IsSameValue = errMsg &"00001"
Exit Function
End If
str = label & str & label
splitStr = Split(str,label)
If IsNull(sValue) Then
IsSameValue = errMsg &"00002"
Exit Function
End If
For i = 0 to Ubound(splitStr)
If splitStr(i) = sValue Then
IsSameValue = 0
Exit For
Else
IsSameValue = 1
End If
Next
Else
IsSameValue = errMsg &"00003"
Exit Function
End If
End Function