作业帮 > 综合 > 作业

用VB生成100个随机数(范围为-1000到1000)并按升序排列,有木有大神会的啊?

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/12 23:30:42
用VB生成100个随机数(范围为-1000到1000)并按升序排列,有木有大神会的啊?
用VB随机生成100个随机数(范围为-1000到1000)并按升序排列,有木有大神会的啊?
用VB生成100个随机数(范围为-1000到1000)并按升序排列,有木有大神会的啊?
Private Sub Command1_Click()
Dim a(99) As Integer
Dim i As Integer, j As Integer, tmp As Integer
For i = 0 To 99
a(i) = Int(2001 * Rnd) - 1000
Next
For i = 0 To 99
For j = i To 99
If a(i) > a(j) Then
tmp = a(i)
a(i) = a(j)
a(j) = tmp
End If
Next
Next
End Sub
再问: 大神,我用text1显示刚生成的随机数,再用text2显示升序后的排列Command1是随机数生成按钮,Command2是升序排列按钮,我做出来后如下图但是运行时,提示我缺少数组。。。。现在应该怎么办啊?
再答: Private Sub Command1_Click() Dim a(99) As Integer Dim i As Integer, j As Integer, tmp As Integer For i = 0 To 99 a(i) = Int(2001 * Rnd) - 1000 Text1 = Text1 & a(i) & " " Next For i = 0 To 99 For j = i To 99 If a(i) > a(j) Then tmp = a(i) a(i) = a(j) a(j) = tmp End If Next Next For i = 0 To 99 Text2 = Text2 & a(i) & " " Next End Sub
再问: 大神,这是只用了Command1,那还要用Command2呢?Command1只显示生成的随机数,并不排列,Command2再排列,而且,我发现窗体不够啊,不能完全显示....如何让显示的数换行显示,让它显示完呢?多谢多谢
再答: Dim a(99) As Integer Private Sub Command1_Click() Dim i As Integer For i = 0 To 99 a(i) = Int(2001 * Rnd) - 1000 Text1 = Text1 & a(i) & " " Next End Sub Private Sub Command2_Click() Dim i As Integer, j As Integer, tmp As Integer For i = 0 To 99 For j = i To 99 If a(i) > a(j) Then tmp = a(i) a(i) = a(j) a(j) = tmp End If Next Next For i = 0 To 99 Text2 = Text2 & a(i) & " " Next End Sub 要换行,可以在text1和text2的属性里设置MultiLine属性为true