VB 改错题 急急急!(三个错)(对了追加悬赏) 5
本程序的功能是:找出随机生成的正整数数组中所有小于数组第1个元素的数据,并按从小到大的次序输出。(本程序界面由2个TextBox和2个CommandButton组成,所有...
本程序的功能是:找出随机生成的正整数数组中所有小于数组第1个元素的数据,并按从小到大的次序输出。
(本程序界面由2个TextBox和2个CommandButton组成,所有对象均采用缺省名。)
Option Explicit
Option Base 1
Dim a(10) As Integer
Private Sub Command1_Click()
Dim i As Integer, a(10) As Integer
Text1.Text = ""
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
Text1.Text = Text1.Text & Str(a(i))
Next i
End Sub
Private Sub Command2_Click()
Dim b() As Integer
Dim k As Integer, i As Integer
Text2.Text = ""
For i = 2 To 10
If a(i) < a(1) Then
k = k + 1
ReDim b(k)
b(k) = a(i)
End If
Next i
If k > 0 Then
Call sort(b)
For i = 1 To UBound(b)
Text2.Text = Text2.Text & Str(b(i))
Next i
End If
End Sub
Private Sub sort(x() As Integer)
Dim i As Integer, j As Integer, t As
Integer
For i = 1 To UBound(x) - 1
For j = i + 1 To UBound(x)
If x(i)< x(j) Then
t = x(i): x(i) = x(j): x(j) = t
End If
Next j
Next i
End Sub 展开
(本程序界面由2个TextBox和2个CommandButton组成,所有对象均采用缺省名。)
Option Explicit
Option Base 1
Dim a(10) As Integer
Private Sub Command1_Click()
Dim i As Integer, a(10) As Integer
Text1.Text = ""
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
Text1.Text = Text1.Text & Str(a(i))
Next i
End Sub
Private Sub Command2_Click()
Dim b() As Integer
Dim k As Integer, i As Integer
Text2.Text = ""
For i = 2 To 10
If a(i) < a(1) Then
k = k + 1
ReDim b(k)
b(k) = a(i)
End If
Next i
If k > 0 Then
Call sort(b)
For i = 1 To UBound(b)
Text2.Text = Text2.Text & Str(b(i))
Next i
End If
End Sub
Private Sub sort(x() As Integer)
Dim i As Integer, j As Integer, t As
Integer
For i = 1 To UBound(x) - 1
For j = i + 1 To UBound(x)
If x(i)< x(j) Then
t = x(i): x(i) = x(j): x(j) = t
End If
Next j
Next i
End Sub 展开
1个回答
展开全部
Option Explicit
Option Base 1
Dim a(10) As Integer
Private Sub Command1_Click()
Dim i As Integer '? , a(10) As Integer
Text1.Text = ""
Randomize '?
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
Text1.Text = Text1.Text & Str(a(i))
Next i
End Sub
Private Sub Command2_Click()
Dim b() As Integer
Dim k As Integer, i As Integer
Text2.Text = ""
ReDim b(1)
For i = 2 To 10
If a(i) < a(1) Then
k = k + 1
ReDim Preserve b(k) '?Presserve
b(k) = a(i)
End If
Next i
If k > 0 Then
Call sort(b)
For i = 1 To UBound(b)
Text2.Text = Text2.Text & Str(b(i))
Next i
End If
End Sub
Private Sub sort(x() As Integer)
Dim i As Integer, j As Integer, t As Integer
For i = 1 To UBound(x) - 1
For j = i + 1 To UBound(x)
If x(i) < x(j) Then
t = x(i): x(i) = x(j): x(j) = t
End If
Next j
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询