Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Login Code

Posted on 2000-05-13
3
156 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 28

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 65
Visual Basic Excel Formatting error 4 127
Microsoft Access combo box help 2 50
fso.FolderExists("\\server\HiddenFolder$") 4 78
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

837 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