VB 考试 求解在线等 编程改错

来源:百度知道 编辑:UC知道 时间:2024/05/16 17:42:33
以下程序是求这样的三位数它是一个完全平方数,并且2个数相同 例如121
144 900
下列由处错误输入到 求解 的CLICK事件代码中 找出错误 原出修改
Private Sub Command1_Click()
Dim i As Integer, k As Integer
For i = 100 To 999
If isequal(i) Then
Print i
k = k + 1
If k = 3 Then Picture1.Print
End If
End Sub
Private Function isequal(ByVal n As Integer) As Boolean
Dim i As Integer
Dim j As Integer
Dim k As Integer
i = n / 100
j = (n - i * 100) \ 10
k = n - 100 * i - 10 * j
If i = j Or i = k Or j = k Then
isequal = True
End If
End Function

Private Function issqr(ByVal n As Integer) As Boolean
Dim d As Integer
d = Sqr(n)
If n = d * d Then
isqr = True
End If
End Function

修改后的正确程序:
Private Sub Command1_Click()
Dim i As Integer, k As Integer
For i = 100 To 999
If isequal(i) Then
Print i
k = k + 1
If k = 3 Then
Picture1.Print
End If
End If
Next i
End Sub
Private Function isequal(ByVal n As Integer) As Boolean
Dim i As Integer
Dim j As Integer
Dim k As Integer
If issqr(n) Then
i = n / 100
j = (n - i * 100) / 10
k = n - 100 * i - 10 * j
If i = j Or i = k Or j = k Then
isequal = True
End If
End If
End Function

Private Function issqr(ByVal n As Integer) As Boolean
Dim d As Integer
d = Sqr(n)
If n = d * d Then
issqr = True
End If
End Function

错误:
第一段 少end if 、next i
第二段 需要加上
If issqr(n) Then
。。。。。
end if
还有 i= (n - i * 100) \ 10
把整除改为“/”,即 i= (n - i * 100) / 10

第三段 isqr = True拼错了是issqr = True