VB随即出现1个数
- 提问者网友:留有余香
- 2021-04-20 17:30
- 五星知识达人网友:往事埋风中
- 2021-04-20 19:00
Randomize
text1.text= Int(Rnd() *9 + 1)
- 1楼网友:佘樂
- 2021-04-20 19:25
Dim CurrentNumber As Integer
Dim arr() As Integer
Dim finish, ifget As Boolean
Function getRnd(i As Integer) As Integer '取1-i之间的随机数一个
Randomize
getRnd = Int(Rnd() * i + 1)
End Function
Function getAllRnd(Counter As Integer, jishu As Integer) As Integer() '取Counter个1-jishu之间的随机数
If (Counter > jishu) Then
MsgBox "数字个数不能大于基数"
Exit Function
End If
ReDim arr(Counter) As Integer
i = 0
Do While i < Counter
arr(i + 1) = getRnd(jishu)
found = False
For x = 1 To i
If arr(x) = arr(i + 1) Then
found = True
Exit For
End If
Next
If Not found Then
i = i + 1
End If
Loop
getAllRnd = arr
End Function
Sub test()
If finish Then
Exit Sub
End If
If Not ifget Then
arr = getAllRnd(10, 10)
CurrentNumber = CurrentNumber + 1
Print arr(CurrentNumber)
ifget = True
Else
CurrentNumber = CurrentNumber + 1
Print arr(CurrentNumber)
If CurrentNumber = 10 Then
finish = True
End If
End If
End Sub
Private Sub Command1_Click()
Call test
End Sub