数据比较大小程序里的2个小问题
我写了个程序比较10个数字的大小,发现个语句没有被正确执行,Text1.Text = ""这句 ,我发现运行程序后,如果直接按command2,Text1.text里面的Text1.Text没有被清空。
Dim a(9) As Integer
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim b As Integer
For j = 1 To 9 '10个数,总共需要进行9轮比较。每轮得到一个最大值放在最右。
For i = 0 To 9 - j '每轮比较中,都要进行10-1-j对相邻数据的比较。
If a(i) > a(i + 1) Then '如果前面一个数大,则把大的数据换到右边。
b = a(i)
a(i) = a(i + 1)
a(i + 1) = b
End If
Next i
Next j
For i = 0 To 9
Text1.Text = Text1.Text + CStr(a(i)) + " "
If i = 4 Then Text1.Text = Text1.Text + Chr(13) + Chr(10)
Next i
End Sub
Private Sub Command2_Click()
Dim i As Integer
Dim m As Integer
Text1.Text = ""
For i = 0 To 9
Z:
m = InputBox("请输入第" & CStr(i + 1) & "个数据", "提示", "")
If IsNumeric(m) Then
a(i) = m
Else
MsgBox "请输入数字", vbOKOnly, "错误"
GoTo Z
End If
Next i
End Sub
Private Sub Form_Load()
End Sub
[ 本帖最后由 zys304 于 2015-1-25 10:23 编辑 ]