开发者

Question about Timer Control in VB6

I have some query about my code, I am using VB6.0 and I have a question using TimerControl... The user will first Login[frmLogin] and开发者_JS百科 then the UserID and Password must recognize whether it is Admin or Guest. Once it was recognized as Admin, the user will be redirected to the frmAdmin and if not, he will be redirected to frmEmployee after the Timer[tmLogin]/Progressbar[pgLogin] reaches 100%. I'm just perplexed because I am using database with two tables[tblEmployee & tblPosition]. Each Table has an index: idxid for tblEmployee and idxpost for tblPosition... I don't know where to insert the conditional statement... Please help me out, once it was resolved, it will be my rule for the further problem that I might encounter... Thanks in advance. Here is my code

Private Sub cmdContinue_Click()
Dim boolLogedIn As Boolean
    If Me.txtUserID.Text = "" And Me.txtPassword.Text = "" Then
        Me.lblWarning.Caption = "*User ID and Password must not be a null."
        Me.tmLoginformSize.Enabled = True
        Me.txtUserID.SetFocus
        Beep
    ElseIf Me.txtUserID.Text = "" Then
        Me.lblWarning.Caption = "*User ID must not be a null."
        Me.tmLoginformSize.Enabled = True
        Me.txtUserID.SetFocus
        Beep
    ElseIf Me.txtPassword.Text = "" Then
        Me.lblWarning.Caption = "*Password must not be a null."
        Me.tmLoginformSize.Enabled = True
        Me.txtPassword.SetFocus
        Beep
    Else
        Do Until datLogin.Recordset.EOF
            With datLogin.Recordset
                If Me.txtUserID.Text = !empid And Me.txtPassword.Text = !Password Then
                    boolLogedIn = True
                    Exit Do
                Else
                    datLogin.Recordset.MoveNext
                End If
            End With
        Loop
        If boolLogedIn = True Then
            Me.tmLogin.Enabled = True
            Me.lblConnecting.Visible = True
            Me.lblLoginPercent.Visible = True
            Me.pbLogin.Visible = True
        Else
            Me.lblWarning.Caption = "*User ID and Password did not match."
            Me.datLogin.Recordset.MoveFirst
            Me.tmLoginformSize.Enabled = True
            Beep
        End If
    End If
End Sub

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
        End If
    End With
End Sub

...Here is my screenshots

Question about Timer Control in VB6

Question about Timer Control in VB6


Your question is not clear enough. If you want to load a form according to Administrator or other you can use like this

dim r as new adodb.recordset
r.open "select postid from tblemployee",db,adopendynamic,adlockoptimistic,adcmdtext

'db is your adodb.connection

if r.eof then
    msgbox "name/pass not matched"
    exit sub
else
    'do whatever you like with your postid in r.fields(0)
end if


Here is how I would accomplish what you are looking for with minimal changes to your code :

'Add this declaration 
Dim m_intLoggedInUserType As Integer

Private Sub cmdContinue_Click()
    'Unchanged code

        Do Until datLogin.Recordset.EOF
            With datLogin.Recordset
                If Me.txtUserID.Text = !empid And Me.txtPassword.Text = !Password Then
                    boolLogedIn = True
                    m_intLoggedInUserType = !postId
                    Exit Do
                Else
                    datLogin.Recordset.MoveNext
                End If
            End With
        Loop

        'More unchanged code
End Sub

Private Sub tmLogin_Timer()
    With Me.pbLogin
        'Unchanged code

            Me.lblConnecting.Caption = "Done..."
            frmLogin.Hide

            if m_intLoggendInUserType = 1 Then 
               frmAdmin.Show
            Else
               frmEmployee.Show
            End If

            Me.tmLogin.Enabled = False
        End If
    End With
End Sub

You should take note of Rasel's answer as well, since working directly with the connection and the recordset objects are preferable to the datacontrol.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜