改錯題:
Option Explicit Private Sub Command1_Click() Dim N As Integer, K As Long, St As String For N = 500 To 800 K = N ^ 2 If Validate(N) And Validate(K) Then St = N & "^2=" & K List1.AddItem St End If Next N End Sub Private Function Validate(ByVal N As Long) As Boolean '錯誤點1byval Dim P As String, i As Integer, a() As Integer, j As Integer P = CStr(N) '錯誤點2str(n) ReDim a(Len(P)) For i = 1 To Len(P) a(i) = Mid(P, i, 1) Next i For i = 1 To UBound(a) - 1 For j = i + 1 To UBound(a) If a(i) = a(j) Then Exit Function '錯誤點3Exit For Next Next Validate = True End Function
|