Option Base 1
Dim i As Integer
Dim j As Integer
Dim a(10) As Integer
Private Sub Command1_Click()
'1、-----------------------------------
'a(i) = Int(Rnd(1) 100 + 1) '这里不对因为你使用了Option Base 1语句所以a()数组的最小下标是1,你这里i并没有赋值i定义类型为integer所以默认值为0,所以会显示错误。
'根据你的题目要求要产生10个随机函数,那么应该要使用循环过程,正确的写法应该是:
Randomize '建议使用该函数使程序每次运行时保证随机数都不一样
for i=1 to 10
a(i) = Int(100Rnd) + 1 '建议随机数这样子写
next
'2、----------------------------------------------------
'Text1Text = "" ’
'Text1txet = a(i) 不明白你这两句是什么意思,如果是要在text1中显示所有随机数应该这么写。
text1text=""
for i=1 to 10
text1text=text1text & a(i) & " " '随机数之间用空格隔开
next
'3-----------------------------------------
For i = 1 To 9
For j = 1 To 9 - i
If a(j) > a(j + 1) Then
t = a(j)
a(j) = a(j + 1)
a(j) = t
end if
Next j
Next i
'上面3进行修改如下
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
Next j
Next i
'4-------------------------
For i = 1 To 10
Text2Text = ""
Text2Text = a(i)
End Sub
'上面4进行修改如下
Text2Text = ""
For i = 1 To 10
Text2Text =text2text & a(i) & " "
next
End Sub
'修改后代码如下:
Option Base 1Dim i As Integer
Dim j As Integer
Dim a(10) As Integer
Private Sub Command1_Click()
Randomize
for i=1 to 10
a(i) = Int(100Rnd) + 1
next
text1text=""
for i=1 to 10
text1text=text1text & 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
Next
Text2Text = ""
For i = 1 To 10
Text2Text =text2text & a(i) & " "
next
End Sub
Private Sub form_click()
Randomize
Dim tmp As Integer
Dim a(1 To 10) As Integer
'开始随机生成10个数
For i = 1 To 10
a(i) = Int(Rnd 99)
Next i
'开始插入排序
For i = 2 To 10
If a(i) > a(i - 1) Then
tmp = a(i)
For j = i - 1 To 1 Step -1
If tmp < a(j) Then Exit For
a(j + 1) = a(j)
Next j
a(j + 1) = tmp
End If
Next i
Print "排序结果:"
For i = 1 To 10
Print a(i);
Next i
End Sub
以上就是关于vb对随机产生10个数进行排序全部的内容,包括:vb对随机产生10个数进行排序、vb程序设计中插入排序、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)