一道关于visual basic的题

来源:百度知道 编辑:UC知道 时间:2024/05/29 03:29:16
编程:从键盘上任意输入10个整数,然后按由小到大的顺序显示出来
写出编程代码

你这个就是冒泡,我下午刚好写了一个:
冒泡的主要代码是这个:
For i = LBound(outL) To UBound(outL) 'max last ,min first
For j = i + 1 To UBound(outL)
If outL(j) < outL(i) Then
temp = outL(j)
outL(j) = outL(i)
outL(i) = temp
temp = Empty
End If
Next
Next

你把键盘的输入数值送到这个数组outL中就可以了。
-----------------------------------------------------------
详细给你写一下吧,你加1个textbox,然后再加9个,用控件数组的形式,用於接收输入的10个数,然后加一个按钮用於排列,按钮的事件这样写
Private Sub Command1_Click()
Dim outL(10),temp,i,j,rtn
For i = 0 To 9
If IsNumeric(Text1(i).Text) Then outL(i) = Text1(i).Text Else MsgBox "The input " & (i + 1) & " is not a number!": Text1(i).SetFocus: Exit Sub
Next
'先定义一个10个数的数组,然后这个是把10个数字加进去,如果输入的不是数字,程序会提示,并定义光标在那里
'然后把上面的代码拷贝到这里排列顺序

for i=lbound(outl) to ubound(outl)
rtn=rtn & chr(13) & chr(10)&oubL(i)
next
msgbox rtn
'把排好的显示出来
End Sub