VB对调数

来源:百度知道 编辑:UC知道 时间:2024/05/16 09:17:59
Private Sub Form_Click()
Dim x1 As Integer, x2, y1, y2 As Integer
Dim a1 As Integer, a2, b1, b2 As Integer

For x1 = 10 To 99
a2 = x1 / 10
a1 = x1 - a2 * 10
x2 = a1 * 10 + a2
For y1 = 10 To 99
b2 = y1 / 10
b1 = y1 - b2 * 10
y2 = b1 * 10 + b2

If x1 + y1 = x2 + y2 Then
Print x1; "+"; y1; "="; x2; "+"; y2
End If
Next
Next
End Sub
我不知道这个程序错在哪里?

a2 = x1 / 10应该是a2 = x1 \ 10,同样b2 = y1 / 10应该是b2 = y1 \ 10。另外变量的声明不规范,应该这样写:
Dim x1 As Integer, x2 As Integer, y1 As Integer, y2 As Integer
Dim a1 As Integer, a2 As Integer, b1 As Integer, b2 As Integer

Private Sub Form_Click()

Dim x1 As Integer, x2 As Integer, y1 As Integer, y2 As Integer
Dim a1 As Integer, a2 As Integer, b1 As Integer, b2 As Integer
For x1 = 10 To 99
a2 = x1 / 10
a1 = x1 - a2 * 10
x2 = a1 * 10 + a2
For y1 = 10 To 99
b2 = y1 / 10
b1 = y1 - b2 * 10
y2 = b1 * 10 + b2

If x1 + y1 = x2 + y2 Then
Print x1; "+"; y1; "="; x2; "+"; y2
End If
Next x1
Next y1
End Sub

你运行了?

你的next后面少了东西啊~

要写next x1
next y1

一个next对应一个for

二楼说的不对,Next语句可以省略循环变量的。

此程序在语法上看没有任何错误。检查一下是不是有逻辑上的错误。

这个程序写的很好啊,不对么?