加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB简易抽奖程序

发布时间:2020-12-16 22:42:39 所属栏目:大数据 来源:网络整理
导读:650) this.width=650;" border="0" alt="" src="http://img.jb51.cc/vcimg/static/loading.png" src="http://img1.51cto.com/attachment/201112/090810445.gif"> 1、VB Timer控件代码: Private Sub Timer1_Timer() Dim strsql As String Dim conn As New AD

1、VB Timer控件代码:

Private Sub Timer1_Timer()

Dim strsql As String
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset

Dim r As Single

Me.Text1 = ""
VBA.Randomize
r = Rnd

conn.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "" & "ytzc.mdb"
strsql = "select top 1 * from tblbeing where mark='0' order by rnd(" & r & "-id)"
rst.Open strsql,conn,adOpenKeyset,adLockOptimistic

Me.Text1 = rst.Fields(0) & rst.Fields(1)

rst.Close
conn.Close
Set rst = Nothing
Set conn = Nothing

End Sub

2、以空格键控制抽奖开始、停止

Private Sub Form_KeyPress(KeyAscii As Integer)
Dim strsql As String
Dim conn As New ADODB.Connection
'Dim rst As New ADODB.Recordse

If mykeycode = "waiting" Then
mykeycode = "start"
ElseIf mykeycode = "start" Then
mykeycode = "stop"
ElseIf mykeycode = "stop" Then
mykeycode = "start"
Else

End If

If KeyAscii = 32 And mykeycode = "start" Then

If mykey = 0 Then
MsgBox "请选择要抽奖的等级",vbOKOnly + 64,"提示"
Else
Me.Timer1.Enabled = True
Me.Timer1.Interval = 10
'Me.Command1.Caption = "停止"
End If

ElseIf KeyAscii = 32 And mykeycode = "stop" Then

Me.Timer1.Enabled = False
'Me.Command1.Caption = "摇奖"

If mykey = 1 Then
Me.Text2 = Me.Text2 & Me.Text1 & vbCrLf
ElseIf mykey = 2 Then
Me.Text3 = Me.Text3 & Me.Text1 & vbCrLf
ElseIf mykey = 3 Then
Me.Text4 = Me.Text4 & Me.Text1 & vbCrLf
Else
End If

conn.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "" & "ytzc.mdb"
strsql = "update tblbeing set mark=" & "'" & mykey & "'" & "where code=" & "'" & Mid(Me.Text1,5,9) & "'"
'rst.Open strsql,adLockOptimistic 无返回记录集,不能使用recordset
conn.Execute strsql

conn.Close
'Set rst = Nothing
Set conn = Nothing

Else

End If
End Sub

3、或者使用command控件控制抽奖开始、停止

Private Sub Command1_Click()

Dim strsql As String
Dim conn As New ADODB.Connection
'Dim rst As New ADODB.Recordset

If Me.Command1.Caption = "摇奖" Then

If mykey = 0 Then
MsgBox "请选择要抽奖的等级","提示"
Me.Text1 = ""
Else
Me.Timer1.Enabled = True
Me.Timer1.Interval = 10
Me.Command1.Caption = "停止"
End If

ElseIf Me.Command1.Caption = "停止" Then

Me.Timer1.Enabled = False
Me.Command1.Caption = "摇奖"

If mykey = 1 Then
Me.Text2 = Me.Text2 & Me.Text1 & vbCrLf
ElseIf mykey = 2 Then
Me.Text3 = Me.Text3 & Me.Text1 & vbCrLf
ElseIf mykey = 3 Then
Me.Text4 = Me.Text4 & Me.Text1 & vbCrLf
Else
End If

conn.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "" & "ytzc.mdb"
strsql = "update tblbeing set mark=" & "'" & mykey & "'" & "where code=" & "'" & Mid(Me.Text1,不能使用recordset
conn.Execute strsql

conn.Close
'Set rst = Nothing
Set conn = Nothing

Else

End If

End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读