回复 10楼 xzlxzlxzl
请教大师 n(k) = n(k) & m(i) & "," 这里下标越界问题
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, m() As String, n() As String, s As String, t As String
s = "赵,钱,孙,陈" '统计过程中,受限于这个值,如这里是4个姓,统计重复“孙,孙,孙,”就出错,
‘假如 s = "赵,钱,孙,陈,黄" 这里是5个姓,统计重复“孙,孙,孙,”没问题,
t = Text1.Text & ","
m = Split(s, ",")
ReDim n(UBound(m))
For i = 0 To UBound(m)
j = 1
k = 0
While InStr(j, t, m(i) & ",")
k = k + 1
j = InStr(j, t, m(i) & ",") + 1
Wend
n(k) = n(k) & m(i) & ","
Next
Text2 = ""
For i = 0 To UBound(n)
If n(i) <> "" Then
Text2 = Text2 & "【共" & i & "人次】:" & n(i) & "(" & Len(n(i)) / 2 & "个姓)" & vbCrLf
End If
Next
End Sub
Private Sub Form_Load()
Text1.Text = "孙,孙,孙,孙"
End Sub