搜索

请教VB高手! 关于数字怎么排序?

发布网友 发布时间:2024-10-24 08:57

我来回答

3个回答

热心网友 时间:2024-10-24 10:37

新建工程,
添加2个文本框, text1和text2 , text2的multiline为true
添加1个按钮,command1

程序没加校验,你可以在text1输入5,然后按command1,在text2中显示效果:

Private Sub Command1_Click()
Dim x%, y%, m%, n%
Text2 = ""

For x = 1 To Val(Text1)
For y = 1 To Val(Text1)
For m = 1 To Val(Text1)
For n = 1 To Val(Text1)
Text2 = Text2 & x & y & m & n & " "
Next
Text2 = Text2 & vbNewLine
Next
Next
Next
End Sub

热心网友 时间:2024-10-24 10:34

VB给几个数字排序,代码该怎么写?
悬赏分:10 - 解决时间:2007-8-10 12:01
数组ABC(100002,100001,100021,100008,100016,100011)
请对其排序输出。
问题补充:不管是升续还是降续都可以的
提问者: zzl1001 - 试用期 一级
最佳答案
'Form中放一个text1,设置multiline=true,scrollbars=2

Dim a()
n = InputBox("输入数据个数")
ReDim a(n)

For i = 1 To n
a(i) = InputBox("输入数据" & i)
Next

For i = 1 To n - 1
p = i
For j = i + 1 To n
If a(p) > a(j) Then p = j
Next j
t = a(i): a(i) = a(p): a(p) = t
Next i

Text1 = Text1 & "结果" & vbCrLf
For i = 1 To n
Text1 = Text1 & a(i) & vbCrLf

热心网友 时间:2024-10-24 10:36

已经测试,结果没问题,不过执行起来比较慢!
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = ""
Dim i, j, k, l, m As Integer
For i = 1 To CInt(TextBox1.Text)
For j = 1 To CInt(TextBox1.Text)
For k = 1 To CInt(TextBox1.Text)
For l = 1 To CInt(TextBox1.Text)
For m = 1 To CInt(TextBox1.Text)
TextBox2.Text = TextBox2.Text & "....." & i & j & k & l & m
Next
Next
Next
Next
Next
End Sub
声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。
E-MAIL:11247931@qq.com
Top