Solved

Login Code

Posted on 2000-05-13
3
155 Views
Last Modified: 2010-05-02
This is probably a very simple problem,
but being a true novice to the VB programming I can't seem to get this to work.
I am trying to write a simple Login code. You type in a username & password
for validation. You have 3 chances to
get it right.If you type in the incorrect username or password a msgbox will say invalid. How can I get the code to allow 3 seperate passes and then a final msgbox saying Access denied
and end the program.
0
Comment
Question by:DavidTimonium
3 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2807598
How about adding a private variable m_MissedPasses As Integer. In the login command button you put code to check if the password is correct, if it's not then add +1 to the m_MissedPasses variable. Then use code like...

   If (m_MissedPasses = 3) Then
      MsgBox "Stupid User did not enter correct Password"
      End
   End If

....to end the program.

Actually I would not use the End statement, but that's the easy way to do it. You should use Unload Me instead, but since I do not know what your program look like I can not say exactly how it should look like.
0
 
LVL 27

Accepted Solution

by:
Ark earned 50 total points
ID: 2807612
Hi
You start form code:
'Place 2 textboxes and two Commandbuttons on form

Dim CorrectPass As String, CorrectName As String
Dim bOK As Boolean

Private Sub Command1_Click()
  Static nCount As Integer
  If Text1 = "" Or Text2 = "" Then
     MsgBox "Enter UserName and Password!", vbOKOnly + vbExclamation
     Exit Sub
  End If
  nCount = nCount + 1
  If nCount > 2 Then End
  If Text1 = CorrectName And Text2 = CorrectPass Then bOK = True
  If bOK Then
     MsgBox "Correct!" & vbCrLf & "Press OK to continue", vbOKOnly
     End
  Else
     MsgBox "Incorrect!" & vbCrLf & "You have " & CStr(3 - nCount) & " more chance(s)", vbOKOnly
  End If
End Sub

Private Sub Command2_Click()
  End
End Sub

Private Sub Form_Load()
  bOK = False
  Caption = "Enter username and password"
  CorrectName = "Ark"
  CorrectPass = "DavidTimonium"
  Text1 = ""
  Text2 = ""
  Text1.PasswordChar = "*"
  Text2.PasswordChar = "*"
  Command1.Caption = "&Submit"
  Command2.Caption = "&Exit"
End Sub
0
 

Author Comment

by:DavidTimonium
ID: 2807660
Thanx Ark....It worked like a charm
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question