Sunteți pe pagina 1din 3

Dim Dim Dim Dim Dim Dim Dim

i As Integer c As Integer svr As String db As String con As New ADODB.Connection rs As New ADODB.Recordset sqlStr As String

Private Sub Check1_Click() If Check1.Value = 0 Then Frame3.Visible = False Else Check1.Visible = False Frame3.Visible = True End If End Sub Private Sub CmdSave_Click() Call NewConnect Call Startup Check1.Visible = True Check1.Value = 0 Frame3.Visible = False End Sub Private Function RandomInteger(Lowerbound As Long, Upperbound As Long) As Long RandomInteger = ((Upperbound - Lowerbound) * Rnd + Lowerbound) End Function Private Sub Command1_Click() Code.Caption = "" lblcode.Caption = "" lblname.Caption = "" lbladd.Caption = "" Command1.Enabled = False Timer1.Enabled = True Timer2.Enabled = False lblwin.Visible = False End Sub Private Sub Command2_Click() con.Close Timer1.Enabled = False End End Sub Private Sub Form_Load() Timer1.Enabled = False i = 30 label1.ForeColor = &H80000012 Call connect Call Startup End Sub Private Sub Timer1_Timer() i = i - 1 Randomize label1.Caption = RandomInteger(txt1.Text, txt2.Text) Call Arledger If i = 0 Then i = 30 c = 1 sqlStr = "Update Consumers Set Win = 1 where AcctCode ='" & (Code.Captio n) & "'" rs.Open sqlStr, con, adOpenKeyset

Code.ForeColor = &HFF& lblcode.ForeColor = &HFF& lblname.ForeColor = &HFF& lbladd.ForeColor = &HFF& Timer1.Enabled = False Timer2.Enabled = True lblwin.Visible = True Command1.Enabled = True Else Label2.Caption = i Code.ForeColor = &H80000012 lblcode.ForeColor = &H80000012 lblname.ForeColor = &H80000012 lbladd.ForeColor = &H80000012 Timer1.Enabled = True End If End Sub Sub connect() svr = txtserver.Text db = txtdb.Text con.Open "Provider=MSDASQL; DRIVER=Sql Server; SERVER=" & svr & "; DATABASE= " & db & "; UID=sa; PWD=;" Set rs = New ADODB.Recordset End Sub Sub Arledger() sqlStr = "Select AcctCode, AcctName, location from Consumers where Win <> 1 and Number ='" & Val(label1.Caption) & "'" rs.Open sqlStr, con, adOpenKeyset If rs.RecordCount <> 0 Then Code.Caption = rs(0) lblcode.Caption = rs(0) lblname.Caption = rs(1) lbladd.Caption = rs(2) End If rs.Close End Sub Sub Startup() sqlStr = "Select Top 1 Number from consumers order by Number asc" rs.Open sqlStr, con, adOpenKeyset If rs.RecordCount <> 0 Then txt1.Text = rs(0) End If rs.Close sqlStr = "Select Top 1 Number from consumers order by Number desc" rs.Open sqlStr, con, adOpenKeyset If rs.RecordCount <> 0 Then txt2.Text = rs(0) End If rs.Close End Sub Sub NewConnect() con.Close svr = txtserver.Text db = txtdb.Text con.Open "Provider=MSDASQL; DRIVER=Sql Server; SERVER=" & svr & "; DATABASE= " & db & "; UID=sa; PWD=;" Set rs = New ADODB.Recordset End Sub Private Sub Timer2_Timer() If c = 1 Then

c = 0 Code.ForeColor = &HFF& lblwin.ForeColor = &HFF& Else c = 1 Code.ForeColor = &HFF0000 lblwin.ForeColor = &HFF0000 End If End Sub

S-ar putea să vă placă și