vb产生-10 ~ 10 之间的随机整数数
展开全部
Private Sub Command1_Click()
Dim i As Integer, k As Integer
Dim strText As String
Dim a(9) As Integer
For i = 0 To 9
Do While Repeat(a(), k, i) '如果重复的话继续获取
k = Int(Rnd * 50 + 1) '获取1~50的整数
Loop
a(i) = k
Next
For i = 0 To 9
strText = strText & " " & a(i)
Next
Label1.AutoSize = True
Label1.Caption = strText
End Sub
Private Function Repeat(a() As Integer, Num As Integer, Index As Integer) As Boolean
'参数:a()表示要判断的数组,Num表示被重复的数字,index表示判断到几号就不看了
Dim j As Integer
For j = LBound(a) To Index '如果有重复则返回True
If Num = a(j) Then Repeat = True: Exit Function
Next
Repeat = False
End Function
Dim i As Integer, k As Integer
Dim strText As String
Dim a(9) As Integer
For i = 0 To 9
Do While Repeat(a(), k, i) '如果重复的话继续获取
k = Int(Rnd * 50 + 1) '获取1~50的整数
Loop
a(i) = k
Next
For i = 0 To 9
strText = strText & " " & a(i)
Next
Label1.AutoSize = True
Label1.Caption = strText
End Sub
Private Function Repeat(a() As Integer, Num As Integer, Index As Integer) As Boolean
'参数:a()表示要判断的数组,Num表示被重复的数字,index表示判断到几号就不看了
Dim j As Integer
For j = LBound(a) To Index '如果有重复则返回True
If Num = a(j) Then Repeat = True: Exit Function
Next
Repeat = False
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询