VB用inputbox连续输入10个数 然后分别进行升降序排列 然后结果显示在TEXT上

2024-11-29 05:45:40
推荐回答(2个)
回答1:

Private Sub Command1_Click()
Dim a(1 To 10) As Integer
Dim n As Integer
Dim i As Integer
Dim j As Integer
For i = 1 To 10
a(i) = Val(InputBox("输入第" & i & "个数"))
Next i
For i = 1 To 10
For j = 1 To 10
If a(i) < a(j) Then
n = a(i)
a(i) = a(j)
a(j) = n
End If
Next j
Next i
Print "升序"
Text1.Text = "升序:"
For i = 1 To 10
Print a(i);
Text1.Text = Text1.Text & a(i) & " "
Next
Print
Print "降序"
Text1.Text = Text1.Text & "降序:"
For i = 10 To 1 Step -1
Print a(i);
Text1.Text = Text1.Text & a(i) & " "
Next i
Print
End Sub

'旅兆添加拆腊租一个局盯按钮然后单击

回答2:

option base 1
Private Sub Command1_Click()
dim b(10) as long , a as long , t as long , n as long
for a = 1 to 10
b(a)=inputbox ("shu ru di " & a )
next
for a = 1 to 9
for n = a+1 to 10
if b(a) > b(n ) then
t=b(a): b(a)=b(n):b(n)=t
next b
next a
for a = 1 to 10
text1.text = text1.text & b(a)
next
end sub