发布网友 发布时间:2022-05-24 12:39
共1个回答
热心网友 时间:2023-10-13 17:09
代码已经调试通过,符合你的要求。附在下面,并有程序运行截图。如有需要留下邮箱,把源程序发给你。欢迎交流。
---------------------------------------------
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetRandomAndShow()
End Sub
Private Sub GetRandomAndShow()
Dim data(0 To 9) As Integer
For i As Integer = 0 To data.Length - 1
data(i) = GetRandom()
Next
Dim min As Integer = FindMin(data)
Dim max As Integer = FindMax(data)
TextBox1.Text = ""
For j As Integer = 0 To data.Length - 1
TextBox1.Text += data(j).ToString & " "
Next
TextBox2.Text = max.ToString
TextBox3.Text = min.ToString
End Sub
Private Function FindMax(ByVal v As Integer()) As Integer
Dim temp As Integer
temp = v(0)
For i As Integer = 0 To v.Length - 1
If temp < v(i) Then
temp = v(i)
End If
Next
Return temp
End Function
Private Function FindMin(ByVal v As Integer()) As Integer
Dim temp As Integer
temp = v(0)
For i As Integer = 0 To v.Length - 1
If temp > v(i) Then
temp = v(i)
End If
Next
Return temp
End Function
Private Function GetRandom() As Integer
' Initialize the random-number generator.
Randomize()
' Generate random value between 1 and 100.
Dim value As Integer = CInt(Int(100 * Rnd()) + 1)
Return value
End Function
End Class