求一个关于随机出现数字的VB程序代码
发布网友
发布时间:2023-10-11 01:46
我来回答
共2个回答
热心网友
时间:2024-12-05 01:07
Private Sub Command1_Click()
Dim x As Integer
Randomize
Me.Cls
x = Int(Rnd * 40) + 1
Me.FontSize = 64
Me.CurrentX = (Me.ScaleWidth - Me.TextWidth(x)) \ 2
Me.CurrentY = (Me.ScaleHeight - Me.TextHeight(x)) \ 2
Me.Print CStr(x)
End Sub
如果想某个数字不出现,则这样(以13为例):
Private Sub Command1_Click()
Dim x As Integer
Randomize
Me.Cls
Do
x = Int(Rnd * 40) + 1
Loop While x = 13 '如果是13就重选
Me.FontSize = 64
Me.CurrentX = (Me.ScaleWidth - Me.TextWidth(x)) \ 2
Me.CurrentY = (Me.ScaleHeight - Me.TextHeight(x)) \ 2
Me.Print CStr(x)
End Sub
热心网友
时间:2024-12-05 01:07
在屏幕中间放置一个Label标签控件,然后按钮中就一句话
Private Sub Command1_Click()
Label1.Caption = Int(Rnd(Timer) * 40) + 1
End Sub
如果不想某数出现(比如27),那么
Dim x As Integer
Do
x = Int(Rnd(Timer) * 40) + 1
Loop Until x <> 27
Label1.Caption = x
End Sub