判断两个字符串中每个字符的个数是否相等。
“ABC”, “ACB” return true
“AABC”, “ABCD” return false代码:
Option Explicit
Option Base 1Public Function isSample(str1 As String, str2 As String) As BooleanDim array1() As String
Dim array2() As String
Dim i As Integer
Dim flag As BooleanIf Len(str1) = Len(str2) Then flag = True
ReDim array1(Int(Len(str1)))
ReDim array2(Int(Len(str2)))
For i = 1 To Len(str1)
    array1(i) = Mid(str1, i, 1)
    array2(i) = Mid(str2, i, 1)
Next i
'For i = LBound(array1) To UBound(array1)
'    Print array1(i)
'Next i
Sort (array1) ''''''''''''提示缺少数组或用户定义类型的错误
Sort (array2)
If array1 = array2 Then
  isSample = True
Else
  isSample = False
End If
End FunctionPrivate Function Sort(arr1() As String)
Dim i As Integer, j As Integer
Dim temp As String
For i = LBound(arr) To UBound(arr1)
    For j = UBound(arr) To i
       If arr(j) < arr(j - 1) Then
            temp = arr(j - 1)
            arr(j - 1) = arr(j)
            arr(j) = temp
       End If
    Next j
Next i
End FunctionPrivate Sub Command1_Click()
Dim str1 As String, str2 As String
str1 = "ABC"
str2 = "ACB"
If isSample(str1, str2) Then
    MsgBox ("字符串相等")
Else
    MsgBox ("字符串不等")
End If
End Sub
什么原因呢?