vb中如何计算1数组中有多少个不同的字符
发布网友
发布时间:2024-10-19 14:35
我来回答
共1个回答
热心网友
时间:2024-11-08 17:53
Private Sub Form_Load()
sarr = Array("123", "123", "234", "456")
MsgBox GetDiffCount(sarr)
End Sub
Public Function GetDiffCount(sarr)
Dim spl() As String
n = 0
ReDim spl(0)
spl(0) = sarr(0)
For i = 1 To UBound(sarr)
For j = 0 To n
If spl(j) = sarr(i) Then Exit For
Next j
If j = n + 1 Then
n = n + 1
ReDim Preserve spl(n)
spl(n) = sarr(i)
End If
Next i
GetDiffCount = n + 1
End Function