vb抽獎小程序
『壹』 怎麼用vb做一個抽獎小程序 在1-1000內隨機抽取
Private Sub Command1_Click()
Label1 = ""
Label1 = 1 + Int(1000 * Rnd)
End Sub
『貳』 VB 抽獎小程序
完化樓上的,,可以搖人名,,不會出現重復,,不會出現空白
加一個LIST 和一個TIMER ,COMMAND
Dim a(30) As String
Private Sub Command1_Click()
If Command1.Caption = "開始" Then
a(1) = "姓名1"
a(2) = "姓名2"
a(3) = "姓名3"
a(4) = "姓名4"
a(5) = "姓名5"
a(6) = "姓名6"
a(7) = "姓名7"
a(8) = "姓名8"
a(9) = "姓名9"
a(10) = "姓名10"
a(11) = "姓名11"
a(12) = "姓名12"
a(13) = "姓名13"
a(14) = "姓名14"
a(15) = "姓名15"
a(16) = "姓名16"
a(17) = "姓名17"
a(18) = "姓名18"
a(19) = "姓名19"
a(20) = "姓名20"
a(21) = "姓名21"
a(22) = "姓名22"
a(23) = "姓名23"
a(24) = "姓名24"
a(25) = "姓名25"
a(26) = "姓名26"
a(27) = "姓名27"
a(28) = "姓名28"
a(29) = "姓名29"
a(30) = "姓名30"
Command1.Caption = "停止"
Timer1.Enabled = True
Timer1.Interval = 50
Else
Timer1.Enabled = False
Timer1.Interval = 0
Command1.Caption = "開始"
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "開始"
End Sub
Private Sub Timer1_Timer()
List1.Clear
Dim b(7) As Double
For i = 1 To 7
Randomize
1
b(i) = Int(29 * Rnd + 1)
For j = 1 To i - 1
If b(i) = b(j) Then GoTo 1
Next j
List1.AddItem a(b(i))
Next i
End Sub
『叄』 vb 編寫一個抽獎程序
command1用來隨機抽取,text2顯示
text1用來自己輸入
command2用來判斷
基本思想:假設連續有a位相同,經過驗證如果為真則得出結果,如果為假,則假設a=a-1位相同……直到a=0
也可以自己輸入text2數據來檢驗程序
這段程序不局限於7位數
Private Sub Command2_Click()
Dim a$, b$, i%, j%, k%
a = CStr(Text1)
b = CStr(Text2)
For i = Len(a) To 1 Step -1
For j = 1 To Len(a) - i + 1
If Mid(a, j, i) = Mid(b, j, i) Then
k = i
Exit For
End If
Next
If k <> 0 Then Exit For
Next
Print k, Mid(a, j, i)'輸出相同位數和相同數字
If len(a)+1-k>5 Then
MsgBox "對不起,無獎項"
Else
MsgBox Len(a) + 1 - k & "等獎"'判斷獎項
End If
End Sub
Private Sub Command1_Click()
a = CStr(Text1)
Text2 = 10 ^ (Len(a) - 1) + Int(Rnd * 0.9 * 10 ^ Len(a))
End Sub
『肆』 vb6.0簡單抽獎程序
預先將圖片名改為1.jpg~10.jpg,放在程序同一文件夾中。
Private Sub Command1_Click() '抽獎
Timer1.Enabled = True
End Sub
Private Sub Command2_Click() 『停止
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Static i As Integer
i = i + 1
If i > 10 Then i = 1 『假設共回10個圖片,如圖片個數答更改,請相應更改數字
Image1.Picture = LoadPicture(i & ".jpg")
End Sub
『伍』 VB中可用的抽獎程序的代碼
我知道你的意思:是不是每組數字來回滾動,隨即組合。
停止時,組合成一組數字,並以這組數字作為中獎號碼。
建立一個按鈕:command1
private
sub
command1_click()
dim
a
as
integer
dim
b
as
integer
dim
c
as
integer
'a
b
c
為隨機變數
dim
abc
as
string
'abc為組合號碼
a
=
int(rnd
*
9)
+
1
b
=
int(rnd
*
9)
+
1
c
=
int(rnd
*
9)
+
1
abc=a
&
b
&
c
'組合中獎號碼
'假設3到10等獎為003,004......,010
if
a
=
001
then
msgbox
"你中了1等獎!",
vbokonly,
"系統提示"
end
if
if
a
=
002
then
msgbox
"你中了2等獎!",
vbokonly,
"系統提示"
end
if
......
......
if
a
=
010
then
msgbox
"你中了10等獎!",
vbokonly,
"系統提示"
end
if
end
sub
ok...
『陸』 抽獎程序(用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
=
0
To
5
Label1(i)
=
Int(10
*
Rnd)
Select
Case
Label1(i).Caption
Case
0
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編寫一個抽獎小程序,要求每次抽獎的數字不重復
DimnAsInteger
Dima()
PrivateSubCommand1_Click()
Ifn=0Then'第一次點擊時執行
m=Val(Text1)
ReDima(1Tom)
Fori=1Tom'生成數組a,元素為至m這m個數
a(i)=i
Next
Fori=1Tom-1'隨機打亂數組a中元素
r=Int(Rnd*m+1)
tmp=a(i)
a(i)=a(r)
a(r)=tmp
Next
EndIf
n=n+1'計數點擊次數
Ifn>Val(Text1)Then'次數超過指定次數,抽獎結束
MsgBox"抽獎結束!"
ExitSub
EndIf
Text2=a(n)'從數組中抽出第n個數,由於數組中是隨機排列,所以相當於生成一個隨機數,並且不會重復
EndSub
『捌』 怎麼用vb做一個抽獎程序
只要在窗體中做二個命令按鈕、一個標簽和一個定時器對象,復制以下代碼,就可回以運行了:
Private Sub Command1_Click()
If Command1.Caption = "開始答" Then
Command1.Caption = "暫停"
Timer1.Enabled = True
Else
Command1.Caption = "開始"
Timer1.Enabled = False
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Label1.Caption = ""
Label1.FontSize = 50
Timer1.Interval = 50
Timer1.Enabled = False
Command1.Caption = "開始"
Command2.Caption = "結束"
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Int(Rnd * 50) + 1
End Sub
『玖』 vb抽獎程序
Dim LL%, UU%
Dim zjHm$
Dim Sorted As Boolean
Private Sub Command1_Click()
On Error GoTo mEnd
If Sorted = True Then Label2.Caption = "": zjHm = "": Sorted = False
Select Case Command1.Caption
Case "開始"
LL=1
UU=10
Command1.Caption = "停止"
Timer1.Interval = 50
Timer1.Enabled = True
Call Timer1_Timer
Case "停止"
Timer1.Enabled = False
Command1.Caption = "開始"
zjHm = zjHm & Label1.Caption & " "
Label2.Caption = zjHm
End Select
mEnd:
End Sub
按鈕的Caption應為專 開始,這個是判斷屬按鈕名稱來決定動作的
『拾』 VB抽獎程序
才子是不是可以點贊我了。。。。