我写了一个抽奖程序,抽中的号码就删掉了,下次再从数据库浏览剩余的号码,但运行是抽过的号码还是会出现,过程如下: Private Sub Timer1_Timer() Dim sid As Integer, strRs As String Dim rs As DAO.Recordset
Set db = OpenDatabase(App.Path & "\sample.mdb") strRs = "select * from mingdan" Set rs = db.OpenRecordset(strRs)
Do Until rs.EOF Label2.Caption = Int(Rnd * rs!id) rs.MoveNext Loop If rs.RecordCount = 0 Then MsgBox ("找不到合适的记录") Timer1.Enabled = False End If
rs.Close db.Close End Sub
Private Sub Command4_Click() Timer1.Enabled = False Set db = OpenDatabase(App.Path & "\sample.mdb") Dim rs As DAO.Recordset strRs = "select * from mingdan where id=" & Int(Label2.Caption) & "" Set rs = db.OpenRecordset(strRs) If Not rs.EOF Then rs.Delete rs.Close db.Close MsgBox "中奖者是:" & Label2.Caption & "号" Else MsgBox ("该号码已抽过") End If Command3.Enabled = True End Sub
Private Sub Command3_Click() Timer1.Enabled = True Timer1_Timer Command3.Enabled = False End Sub
Private Sub Timer1_Timer() Dim i As Long Dim t As Integer
LabXM = "" LabDetail = "" i = 0 R1: Randomize i = CLng((UBound(ST) * Rnd)) If i < 0 Then GoTo R1 If Check1.Value = 1 Then For t = 1 To List1.ListCount List1.ListIndex = t - 1 If Trim(Mid(List1, InStr(List1, "|") + 1)) = Trim(ST(i) & " ") Then i = -1 Exit For End If Next End If If i < 0 Then GoTo R1 If LX = "" Then LabXM = ST(i) LabDetail = ST(i) End If End Sub
我是程序里 名字是读取文本文件里的 1行代表一个人的信息 Public ST Public iCount As Long Public LX As String
Private Sub Command1_Click() '定义一个变量 先吧所有数据都到里面 Dim txtTemp Dim Textline As String CommonDialog1.CancelError = True On Error GoTo ErrHandler ' 设置标志 CommonDialog1.Flags = cdlOFNHideReadOnly ' 设置过滤器 CommonDialog1.Filter = "TEXT Files (*.txt)|*.txt" ' 指定缺省的过滤器 CommonDialog1.FilterIndex = 2 ' 显示“打开”对话框 CommonDialog1.ShowOpen ' 显示选定文件的名字 ' CommonDialog1.FileName txtTemp = "" Open CommonDialog1.FileName For Input As #1 ' 打开配置文件。 Do While Not EOF(1) Line Input #1, Textline If Trim(Textline & " ") <> "" Then txtTemp = txtTemp & "|" & Textline End If
Loop Close #1 txtTemp = Mid(txtTemp, 2) ST = Split(txtTemp, "|") iCount = UBound(ST) LX = "" ErrHandler: End Sub