关于VB中函数过程的定义和调用 (应该很简单的大家来试试)
利用数组随机产生20个数,编写可对此数组数据进行排序的自定义函数过程,调用该函数将20个数用告到低的次序排列输出...
利用数组随机产生20个数,编写可对此数组数据进行排序的自定义函数过程,调用该函数将20个数用告到低的次序排列输出
展开
展开全部
Private Sub Form_Click()
Dim A(1 To 20) As Integer
Randomize
For i = 1 To 20
A(i) = Int(Rnd * 900) + 100
Next
Call SortArr(A)
For i = 1 To 20
Print A(i);
Next
Print
End Sub
Function SortArr(ByRef A() As Integer)
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
End Function
Dim A(1 To 20) As Integer
Randomize
For i = 1 To 20
A(i) = Int(Rnd * 900) + 100
Next
Call SortArr(A)
For i = 1 To 20
Print A(i);
Next
End Sub
Function SortArr(ByRef A() As Integer)
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
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询