我对我的代码有一些疑问,我使用的是VB6.0,我在使用TimerControl
时遇到了问题。用户将首先Login[frmLogin]
,然后在EmployeeForm[frmEmployee]
达到100%后,他将被重定向到Timer[tmLogin]/Progressbar[pgLogin]
。
这是我的代码:
Private Sub cmdContinue_Click()
If Me.txtUserID.Text = "" Or Me.txtPassword.Text = "" Then
MsgBox "Required field must not be a null.", vbCritical, "ERROR"
Else
Do Until datLogin.Recordset.EOF
With datLogin.Recordset
If Me.txtUserID.Text = !empid And Me.txtPassword.Text = !Password Then
'Here
Else
datLogin.Recordset.MoveNext
End If
End With
Loop
MsgBox "User ID and Password didn't match!", vbCritical, "ERROR LOGIN"
End If
End Sub
以下是Timer
的代码:
Private Sub tmLogin_Timer()
With Me.pbLogin
Me.pbLogin.Value = Me.pbLogin.Value + 1
Me.lblLoginPercent.Caption = Str(Me.pbLogin.Value) + "%"
If Me.pbLogin.Value >= 1 And Me.pbLogin.Value < 50 Then
Me.lblConnecting.Caption = "Connecting..."
ElseIf Me.pbLogin.Value >= 50 And Me.pbLogin.Value < 100 Then
Me.lblConnecting.Caption = "Logging in..."
Else
Me.lblConnecting.Caption = "Done..."
frmLogin.Hide
frmEmployee.Show
Me.tmLogin.Enabled = False
Exit Sub
End If
End With
End Sub
答案 0 :(得分:0)
您应该知道只有在您的应用程序中没有进行其他处理时,才会触发计时器事件。
您可以尝试按以下方式执行此操作:
Private Sub cmdContinue_Click()
Dim boolLoggedIn As Boolean
If Me.txtUserID.Text = "" Or Me.txtPassword.Text = "" Then
MsgBox "Required field must not be a null.", vbCritical, "ERROR"
Else
Do Until datLogin.Recordset.EOF
With datLogin.Recordset
If Me.txtUserID.Text = !empid And Me.txtPassword.Text = !Password Then
boolLoggedIn = true
Exit Do
Else
datLogin.Recordset.MoveNext
End If
End With
Loop
If boolLoggedIn Then
'While the timer is running frmLogin will still accept user
'input, so you should disable the form to prevent that.
'You should also consider closing the recordset if it isn't
'going to be needed further on.
tmLogin.Enabled = true
Else
MsgBox "User ID and Password didn't match!", vbCritical, "ERROR LOGIN"
End If
End If
End Sub
只有在此子退出并且没有其他代码正在运行时,才会启动计时器事件。