Private Sub 开始_Click()
停止.Enabled = True
开始.Enabled = False
结果框.Text = ""
Dim a As Integer
Randomize
Do
If 停止.Enabled = False Then
州桥 结果框.Text = 抽取框.Text
Num = Num + 1
If Num <= 4 Then
If 已抽题目.Text = "" Then
b = ""
Else
b = " # "
End If
已抽题目.Text = 已抽题目.Text & b & 抽取框.Text
Else
Num = 1
已抽题目.Text = 抽取框.Text
End If
Exit Do
Else
a = Fix(Rnd * 10 + 1)
闷清 抽取框.Text = a
End If
DoEvents
Loop
开始.Enabled = True
End Sub
Private Sub 停止_Click()
停止.Enabled = False
End Sub
Private Sub 打开抽取的题目_Click()
ActivePresentation.SlideShowWindow.View.GotoSlide (Val(抽取框.Text + 1))
End Sub
' 说明:
' 册罩猛1、可能需要保存为启用宏的文档
' 2、去除了end命令,在调试状态需要手动点击代码编辑窗口的“重新设置”按钮结束程序
Dim a(1 To 100) As StringDim i As Integer, x As Integer
Const n = 3 'n的值可根据实际需要赋予不同的变量
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Randomize '游唤没初始化随机数生成器
a(1) = "富士康" '以此将n个人神纳的姓链晌名保存在数组a中
a(2) = "庞麦郎"
a(3) = "非主流"
For i = 1 To n
List1.AddItem a(i)
Next
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
x = Rnd() * n + 1 '产生一个[1,n]中的随机整数并存入变量x中
Label2.Caption = a(x) '在标签Label2中显示下标变量a(x)的值(第x个人的姓名)
End Sub
语言实现此程序。以下是VB编程语言的实现示例:
'定义变量,存储每个奖项的人数
Dim firstPrize As Integer = 3
Dim secondPrize As Integer = 5
Dim thirdPrize As Integer = 12
Dim souvenirPrize As Integer = 10
'定义变量,存储抽奖结果
Dim firstPrizeList As New List(Of Integer)
Dim secondPrizeList As New List(Of Integer)
Dim thirdPrizeList As New List(Of Integer)
Dim souvenirPrizeList As New List(Of Integer)
'定义变量,存储编号滚动的起始编号
Dim currentNum As Integer = 1
'循环抽取各种奖项
For i As Integer = 1 To firstPrize
firstPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To secondPrize
'抽取二等奖,并将编号添加到二等奖名单中
secondPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To thirdPrize
'抽取三等奖,并将编洞派号添加到三等奖名单中
thirdPrizeList.Add(currentNum)
currentNum += 1
Next
For i As Integer = 1 To souvenirPrize
'抽取纪念奖,并将编纳档贺号添加到纪念奖名单中
souvenirPrizeList.Add(currentNum)
currentNum += 1
Next
'输出抽奖结果
Console.WriteLine("一等奖名单:" &String.Join(",", firstPrizeList))
Console.WriteLine("二等奖名单:" &String.Join("蠢凯,", secondPrizeList))
Console.WriteLine("三等奖名单:" &String.Join(",", thirdPrizeList))
Console.WriteLine("纪念奖名单:" &String.Join(",", souvenirPrizeList))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)