[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Login Code

Posted on 2000-05-13
3
Medium Priority
?
160 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
[X]
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
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 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

656 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