VB作业,有关数组的问题,求大佬!
功能要求如下:1.定义一个一维数组a,其下标的下界和上界由窗体输入的值确定。2.点击“生成数组”按钮,将生成的数值在[1,100]区间的数组a的所有元素显示在右边的...
功能要求如下:1. 定义一个一维数组a,其下标的下界和上界由窗体输入的值确定。2. 点击“生成数组”按钮,将生成的数值在[1,100]区间的数组a的所有元素显示在右边的
展开
1个回答
展开全部
Option Explicit
Dim a() As Byte
Private Sub Command1_Click()
Text3.Text = ""
Dim i As Integer
ReDim a(Val(Text1.Text) To Val(Text2.Text))
For i = LBound(a) To UBound(a)
a(i) = Int(Rnd * 100) + 1
Text3.Text = Text3.Text & Str(a(i))
Next
End Sub
Private Sub Command2_Click()
Text4.Text = ""
Dim i As Integer, j As Integer, t As Byte
For i = LBound(a) To UBound(a)
For j = i To UBound(a)
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
For i = LBound(a) To UBound(a)
Text4.Text = Text4.Text & Str(a(i))
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询