如何用VB实现排序

来源:百度知道 编辑:UC知道 时间:2024/06/02 21:09:35
请问各位高人帮忙解决下
要求1:通过按钮输入10个数字
要求2:所输入的数字须全部显示在第一个标签栏内
要求3:当输入完后会对这些数字进行升序排序并显示在第2个标签栏内
要求4:界面内只有2个标签栏,1个按钮

private sub command1_click()
dim a(1 to 10) as integer,i as integer,j as integer,r as string,t as integer
label1.caption=""
for i=1 to 10
a(i)=inputbox("请输入一个整数:")
label1.caption=label1.caption+str(a(i))
next
for i=1 to 9
for j=i+1 to 10
if a(i)>a(j) then
t=a(i):a(i)=a(j):a(j)=t
end if
next j
next i
r=""
for i=1 to 10
r=r+str(a(i))
next i
label2.caption=r
end sub

Private Sub Command1_Click()
Dim n As Integer, a() As Integer, Temp As Integer
Label1.Caption = ""
Label2.Caption = ""
n = 10 '需要排序数据的个数,可以自定义
ReDim a(n)
'以下6行是自动产生数据的,免得手工一个个输入
Randomize
For i = 1 To n
a(i) = Int(Rnd * 100)
Label1.Caption = Label1.Caption & a(i)
If i < n Then Label1.Caption = Label1.Caption & ","
Next
'以下4行是手工输入数据用的
'For i = 1 To n
'