如图关于计算机VB数组与元素插入的~很急啊.....在线等大神帮忙!非常感谢!
展开全部
界面就上面的了
代码如下:
Dim a() As Long '定义一个数组
Private Sub Command1_Click()
Dim t As Long
ReDim a(9) '重定义数组
For i = 0 To 9
Randomize
a(i) = CLng(Rnd * 100 + 100) '随机生成10个数
Next
For i = 0 To 9 '对这个数组进行排序
For j = i + 1 To 9
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
Text1.Text = ""
For i = 0 To 9
If Text1.Text = "" Then Text1.Text = a(i) Else Text1.Text = Text1.Text & " " & a(i) '将这个数组显示在Text1中
Next
End Sub
Private Sub Command2_Click()
ReDim Preserve a(UBound(a) + 1) '数组中增加一个元素
Randomize
a(UBound(a)) = CLng(Rnd * 100 + 100) '数组最后一个元素的值为新增加的随机数
For i = 0 To UBound(a) '对这个数组进行排序
For j = i + 1 To UBound(a)
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
Text2.Text = ""
For i = 0 To UBound(a)
If Text2.Text = "" Then Text2.Text = a(i) Else Text2.Text = Text2.Text & " " & a(i) '将这个数组显示在Text2中
Next
End Sub
代码如下:
Dim a() As Long '定义一个数组
Private Sub Command1_Click()
Dim t As Long
ReDim a(9) '重定义数组
For i = 0 To 9
Randomize
a(i) = CLng(Rnd * 100 + 100) '随机生成10个数
Next
For i = 0 To 9 '对这个数组进行排序
For j = i + 1 To 9
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
Text1.Text = ""
For i = 0 To 9
If Text1.Text = "" Then Text1.Text = a(i) Else Text1.Text = Text1.Text & " " & a(i) '将这个数组显示在Text1中
Next
End Sub
Private Sub Command2_Click()
ReDim Preserve a(UBound(a) + 1) '数组中增加一个元素
Randomize
a(UBound(a)) = CLng(Rnd * 100 + 100) '数组最后一个元素的值为新增加的随机数
For i = 0 To UBound(a) '对这个数组进行排序
For j = i + 1 To UBound(a)
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
Text2.Text = ""
For i = 0 To UBound(a)
If Text2.Text = "" Then Text2.Text = a(i) Else Text2.Text = Text2.Text & " " & a(i) '将这个数组显示在Text2中
Next
End Sub
更多追问追答
追问
我试试~!
谢谢大神!感激涕零!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询