当前位置:首页 > 代码 > 正文

vb抽奖代码(用vb编写一个抽奖程序)

admin 发布:2022-12-19 19:39 127


本篇文章给大家谈谈vb抽奖代码,以及用vb编写一个抽奖程序对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

VB编程年会抽奖代码?

语言实现此程序。

以下是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))

VB中可用的抽奖程序的代码

Dim a(1 To 100) As String

Dim 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编写)

在窗体上添加一个command1,一个timer1,label1(0~5)

控件数组(添加一个label1,然后再复制5个,共6个,用来显示数字),代码如下:

Private

Sub

Command1_Click()

If

Command1.Caption

=

"抽奖"

Then

Command1.Caption

=

"停止"

Timer1.Enabled

=

True

Else

Timer1.Enabled

=

False

Command1.Caption

=

"抽奖"

End

If

End

Sub

Private

Sub

Form_Load()

Command1.Caption

=

"抽奖"

Timer1.Interval

=

50

Timer1.Enabled

=

False

End

Sub

Private

Sub

Timer1_Timer()

Randomize

For

i

=

To

5

Label1(i)

=

Int(10

*

Rnd)

Select

Case

Label1(i).Caption

Case

Label1(i).BackColor

=

RGB(0,

0,

0)

Label1(i).ForeColor

=

RGB(255,

255,

255)

Case

1

Label1(i).BackColor

=

RGB(128,

42,

42)

Label1(i).ForeColor

=

RGB(127,

213,

213)

Case

2

Label1(i).BackColor

=

RGB(255,

0,

0)

Label1(i).ForeColor

=

RGB(0,

255,

255)

Case

3

Label1(i).BackColor

=

RGB(255,

97,

0)

Label1(i).ForeColor

=

RGB(0,

158,

255)

Case

4

Label1(i).BackColor

=

RGB(255,

255,

0)

Label1(i).ForeColor

=

RGB(0,

0,

255)

Case

5

Label1(i).BackColor

=

RGB(0,

255,

0)

Label1(i).ForeColor

=

RGB(255,

0,

255)

Case

6

Label1(i).BackColor

=

RGB(0,

0,

255)

Label1(i).ForeColor

=

RGB(255,

0,

0)

Case

7

Label1(i).BackColor

=

RGB(160,

32,

240)

Label1(i).ForeColor

=

RGB(95,

223,

15)

Case

8

Label1(i).BackColor

=

RGB(192,

192,

192)

Label1(i).ForeColor

=

RGB(63,

63,

63)

Case

9

Label1(i).BackColor

=

RGB(255,

255,

255)

Label1(i).ForeColor

=

RGB(0,

0,

0)

End

Select

Next

End

Sub

关于vb抽奖代码和用vb编写一个抽奖程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/20975.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载