永发信息网

VB随即出现1个数

答案:2  悬赏:30  手机版
解决时间 2021-04-20 22:03
  • 提问者网友:留有余香
  • 2021-04-20 17:30
我想单击Command1在Text1随即显示1-10任意1个数字,我试下随即出现的数,它一直会变,我要不会一直变,但每次单击Command1更变一次数字,会的写出代码!
最佳答案
  • 五星知识达人网友:往事埋风中
  • 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

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯