PDA

View Full Version : Help! - How Do I?


thejazzman
03-29-04, 04:57 AM
I have been learning vb for the passed couple of weeks but ive come across a problem which i cant seem to work out.

I need to loop the program so when you click the login command button (cmdLogin) it checks the user number and password, if these are wrong it gives you another chance to re-enter the usernumber and password, again if these are wrong it allows you to enter you user number and password one last time, it then exits the program unless you enter the correct details.

The code i have up to now is written below. As you can see there is no loop in it.

Could you please show me how to insert the loop which is described above. Thank You.


Private Sub cmdLogin_Click()

Dim strCustomerNumber As String
Dim strPassword As String

strCustomerNumber = txtCustomerNumber
strPassword = txtPassword

If strCustomerNumber = "10001" And strPassword = "ONE" Then
LoginSuccessful = True
Me.Hide
frmWelcome.Show
ElseIf strCustomerNumber = "10002" And strPassword = "TWO" Then
LoginSuccessful = True
Me.Hide
frmWelcome.Show
ElseIf strCustomerNumber = "10003" And strPassword = "THREE" Then
LoginSuccessful = True
Me.Hide
frmWelcome.Show
ElseIf strCustomerNumber = "10004" And strPassword = "FOUR" Then
LoginSuccessful = True
Me.Hide
frmWelcome.Show
ElseIf strCustomerNumber = "10005" And strPassword = "FIVE" Then
LoginSuccessful = True
Me.Hide
frmWelcome.Show
Else
LoginSuccessful = False
MsgBox "Invalid User Number or Password, try again!", vbInformation, "Login"
End If

End Sub

thejazzman
04-01-04, 04:31 AM
Does no one have the answer or have i not given enough time yet?

Rune
04-01-04, 06:36 AM
Try this.


Option Explicit

Dim tInCorrect As Byte

Private Sub Form_Load()
tInCorrect = 0
End Sub

Private Sub cmdLogin_Click()
Dim strCustomerNumber, strPassword As String

strCustomerNumber = txtCustomerNumber
strPassword = txtPassword

If ( strCustomerNumber = "10001" And strPassword = "ONE" ) Then Goto CorrectLogin::
If ( strCustomerNumber = "10002" And strPassword = "TWO" ) Then Goto CorrectLogin::
If ( strCustomerNumber = "10003" And strPassword = "THREE" ) Then Goto CorrectLogin::
If ( strCustomerNumber = "10004" And strPassword = "FOUR" ) Then Goto CorrectLogin::
If ( strCustomerNumber = "10005" And strPassword = "FIVE" ) Then Goto CorrectLogin::

tInCorrect = tInCorrect + 1

If ( tInCorrect = 3 ) Then
MsgBox "You have entered an invalid username or password 3 times! The Program will now exit.", vbInformation, "Incorrect Login"
End
Else
MsgBox "Invalid username or password, try again!", vbInformation, "Incorrect Login"
End If
LoginSuccessful = False
Exit Sub

CorrectLogin::
LoginSuccessful = True
Me.Hide
frmWelcome.Show
End Sub