
4个回答
展开全部
把下面的代码复制到记事本里,保存后,将扩展名改为frm就可以直接用VB打开运行。
'---------------------以下是代码---------------------
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "模拟摇奖机"
ClientHeight = 2760
ClientLeft = 45
ClientTop = 330
ClientWidth = 4920
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2760
ScaleWidth = 4920
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.Timer tmrAnimal
Enabled = 0 'False
Interval = 500
Left = 960
Top = 2160
End
Begin VB.CommandButton cmdStart
Caption = "开始摇奖"
Height = 495
Left = 1673
TabIndex = 1
Top = 1920
Width = 1575
End
Begin VB.Label lblTitle
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 2
Top = 240
Width = 4095
End
Begin VB.Label lblSelected
Alignment = 2 'Center
BackColor = &H00C0FFFF&
BeginProperty Font
Name = "黑体"
Size = 18
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 390
Index = 0
Left = 345
TabIndex = 0
Top = 840
Width = 420
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'本程序可以任意几选几。
Private Const MAX_NUM As Long = 20 '选的最大数
Private Const SEL_NUM As Long = 8 '选的个数
Private ArrayNum(MAX_NUM - 1) As Integer
Private CurrentIdx As Integer
Private Function SelectOne() As Integer
Dim intRnd As Integer
Dim intTemp As Integer
Randomize
intRnd = Int(Rnd() * (MAX_NUM - CurrentIdx)) '坠机产生数组下标
intTemp = ArrayNum(MAX_NUM - CurrentIdx - 1) '把被选中的数组与最后面的数组进行交换
ArrayNum(MAX_NUM - CurrentIdx - 1) = ArrayNum(intRnd)
ArrayNum(intRnd) = intTemp
CurrentIdx = CurrentIdx + 1
SelectOne = ArrayNum(MAX_NUM - CurrentIdx)
End Function
Private Sub cmdStart_Click()
ResetNum
cmdStart.Enabled = False
tmrAnimal.Enabled = True
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To SEL_NUM - 1
Load lblSelected(i)
lblSelected(i).Visible = True
lblSelected(i).Left = lblSelected(0).Left + i * (lblSelected(i).Width + 120)
Next
lblTitle.Caption = "本次" & MAX_NUM & "选" & SEL_NUM & "中奖号码是:"
End Sub
Private Sub tmrAnimal_Timer()
If CurrentIdx = SEL_NUM Then
tmrAnimal.Enabled = False
cmdStart.Enabled = True
Exit Sub
Else
lblSelected(CurrentIdx - 1).Caption = Format(SelectOne, "00")
End If
End Sub
Private Sub ResetNum()
Dim i As Integer
For i = 1 To MAX_NUM
ArrayNum(i - 1) = i
Next
For i = 0 To lblSelected.UBound
lblSelected(i).Caption = ""
Next
CurrentIdx = 0
End Sub
'---------------------代码结束---------------------
'---------------------以下是代码---------------------
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "模拟摇奖机"
ClientHeight = 2760
ClientLeft = 45
ClientTop = 330
ClientWidth = 4920
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2760
ScaleWidth = 4920
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.Timer tmrAnimal
Enabled = 0 'False
Interval = 500
Left = 960
Top = 2160
End
Begin VB.CommandButton cmdStart
Caption = "开始摇奖"
Height = 495
Left = 1673
TabIndex = 1
Top = 1920
Width = 1575
End
Begin VB.Label lblTitle
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 2
Top = 240
Width = 4095
End
Begin VB.Label lblSelected
Alignment = 2 'Center
BackColor = &H00C0FFFF&
BeginProperty Font
Name = "黑体"
Size = 18
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 390
Index = 0
Left = 345
TabIndex = 0
Top = 840
Width = 420
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'本程序可以任意几选几。
Private Const MAX_NUM As Long = 20 '选的最大数
Private Const SEL_NUM As Long = 8 '选的个数
Private ArrayNum(MAX_NUM - 1) As Integer
Private CurrentIdx As Integer
Private Function SelectOne() As Integer
Dim intRnd As Integer
Dim intTemp As Integer
Randomize
intRnd = Int(Rnd() * (MAX_NUM - CurrentIdx)) '坠机产生数组下标
intTemp = ArrayNum(MAX_NUM - CurrentIdx - 1) '把被选中的数组与最后面的数组进行交换
ArrayNum(MAX_NUM - CurrentIdx - 1) = ArrayNum(intRnd)
ArrayNum(intRnd) = intTemp
CurrentIdx = CurrentIdx + 1
SelectOne = ArrayNum(MAX_NUM - CurrentIdx)
End Function
Private Sub cmdStart_Click()
ResetNum
cmdStart.Enabled = False
tmrAnimal.Enabled = True
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To SEL_NUM - 1
Load lblSelected(i)
lblSelected(i).Visible = True
lblSelected(i).Left = lblSelected(0).Left + i * (lblSelected(i).Width + 120)
Next
lblTitle.Caption = "本次" & MAX_NUM & "选" & SEL_NUM & "中奖号码是:"
End Sub
Private Sub tmrAnimal_Timer()
If CurrentIdx = SEL_NUM Then
tmrAnimal.Enabled = False
cmdStart.Enabled = True
Exit Sub
Else
lblSelected(CurrentIdx - 1).Caption = Format(SelectOne, "00")
End If
End Sub
Private Sub ResetNum()
Dim i As Integer
For i = 1 To MAX_NUM
ArrayNum(i - 1) = i
Next
For i = 0 To lblSelected.UBound
lblSelected(i).Caption = ""
Next
CurrentIdx = 0
End Sub
'---------------------代码结束---------------------

2023-10-23 广告
作为上海远宽能源科技有限公司的工作人员,我可以简单回答一下您对各个半实物仿真平台的区别的问题。首先,半实物仿真平台都是用于模拟真实系统或设备的运行情况,但它们之间存在一些区别。1. 硬件架构:不同的半实物仿真平台可能采用不同的硬件架构,包括...
点击进入详情页
本回答由远宽能源提供
展开全部
Private Sub Command1_Click()
Randomize Timer
Dim x(1 To 20) As Integer
Dim i As Integer
For i = 1 To 20
x(i) = i
Next i
Me.Cls
Dim n As Integer, t As Integer
For i = 1 To 20
n = Int(Rnd() * 20) + 1
t = x(i)
x(i) = x(n)
x(n) = t
Next i
For i = 1 To 8
Print x(i);
Next i
End Sub
'在窗体上添加一个按钮,然后粘贴代码,单击可以看效果,不明白的请百度hi我
Randomize Timer
Dim x(1 To 20) As Integer
Dim i As Integer
For i = 1 To 20
x(i) = i
Next i
Me.Cls
Dim n As Integer, t As Integer
For i = 1 To 20
n = Int(Rnd() * 20) + 1
t = x(i)
x(i) = x(n)
x(n) = t
Next i
For i = 1 To 8
Print x(i);
Next i
End Sub
'在窗体上添加一个按钮,然后粘贴代码,单击可以看效果,不明白的请百度hi我
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'我来个最简单的吧
Private Sub Command1_Click()
Dim a(0 To 7) As Variant
For i = 0 To 7
a(i) = a(i) & Int((20 * Rnd) + 1)
b = b & " " & a(i)
Next
Print b
End Sub
Private Sub Command1_Click()
Dim a(0 To 7) As Variant
For i = 0 To 7
a(i) = a(i) & Int((20 * Rnd) + 1)
b = b & " " & a(i)
Next
Print b
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
For i = 1 To 8
Print Int((20 * Rnd) + 1)
Next
End Sub
For i = 1 To 8
Print Int((20 * Rnd) + 1)
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询