Login for a password form...multiple users

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • william  cline

    #1

    Login for a password form...multiple users

    Hi, I am a beginner and below I have code for a long in form. My goal is
    for the form to read a file of a list of users and thier passwords
    ....compare the text box inputs to the file and either start over or load the
    main file.... I attempted to use a slect case..but its not working for me..
    If someone has a better way of doing it..I would apperciate the help. Thank
    you!

    Option Explicit

    Public LoginSucceeded As Boolean


    Private Sub cmdCancel_Click ()
    'set the global var to false
    'to denote a failed login
    LoginSucceeded = False
    Me.Hide
    End Sub

    Private Sub cmdOK_Click()
    Dim User As String
    Dim Password As String
    Dim inCtr As Integer
    Dim LoginSucceded As Boolean
    Dim Login

    Login = User + Password


    Select Case LoginSucceded


    'demo not a variable....exa mple..txt.Usern ame.text is what is needed

    Case Demo

    User = txtUserName = "Trial"
    txtPassword = "Demo"
    Form_Load.frmDa ta
    Me.Hide

    Case File
    Open "C:\Windows\Dat aPwd\Pswd.pwd" For Random As #1
    For i = 1 To 10
    Get #1, User, Password
    If Text.txtUserNam e = User And Text.txtPasswor d = Password Then
    LoginSucceeded = True
    Form_Load.frmDa ta
    Me.Hide
    Else: Next i
    End If


    Else
    MsgBox "Invalid Password, try again!", , "Login"
    txtPassword.Set Focus
    SendKeys "{Home}+{En d}"
    End If
    End Sub





  • Mike

    #2
    Re: Login for a password form...multiple users

    If this is your exact code, you have problems all over the place..

    Your Select Case does not have a matching End Select

    Also, you have 2 variables
    - A module level variable called LoginSucceeded
    - A procdure level variable called LoginSucceded
    You are just asking for all kinds of debugging trouble by having 2 variable
    named so similarily


    - Why are you doing a
    Select Case LoginSucceded ?
    You are using the procedure level variable, and when the procedure is
    entered (i.e., after the cmdOK is clicked), this variable will ALWAYS be
    false.
    The "Select Case LoginSucceded" makes no sense

    - On the Case statements, Demo and File are not variables, if you intend for
    these to be strings, you have to enclose these in double-quotes, use "Demo"
    and "File".

    - If you want to check the UID and PWD that a user enters, you will want to
    open your file first, read it to see if the txtUserName.Tex t and
    txtPassword.Tex t exist in the data file. If so, all is good, if not make the
    user re-enter.

    - I think you are trying to highlight the contents of the txtPassword
    textbox by
    SendKeys "{Home}+{En d}"
    - You should do the following
    txtPassword.Set Focus
    txtPassword.Sel Start= 0
    txtPassword.Sel Length = Len(txtPassword .Text)

    Try to straighten up some of that, and see how that goes

    Mike



    "william cline" <wilbl1@earthli nk.net> wrote in message
    news:7Wh7f.1967 3$QE1.15285@new sread2.news.atl .earthlink.net. ..[color=blue]
    > Hi, I am a beginner and below I have code for a long in form. My goal
    > is
    > for the form to read a file of a list of users and thier passwords
    > ...compare the text box inputs to the file and either start over or load
    > the
    > main file.... I attempted to use a slect case..but its not working for
    > me..
    > If someone has a better way of doing it..I would apperciate the help.
    > Thank
    > you!
    >
    > Option Explicit
    >
    > Public LoginSucceeded As Boolean
    >
    >
    > Private Sub cmdCancel_Click ()
    > 'set the global var to false
    > 'to denote a failed login
    > LoginSucceeded = False
    > Me.Hide
    > End Sub
    >
    > Private Sub cmdOK_Click()
    > Dim User As String
    > Dim Password As String
    > Dim inCtr As Integer
    > Dim LoginSucceded As Boolean
    > Dim Login
    >
    > Login = User + Password
    >
    >
    > Select Case LoginSucceded
    >
    >
    > 'demo not a variable....exa mple..txt.Usern ame.text is what is needed
    >
    > Case Demo
    >
    > User = txtUserName = "Trial"
    > txtPassword = "Demo"
    > Form_Load.frmDa ta
    > Me.Hide
    >
    > Case File
    > Open "C:\Windows\Dat aPwd\Pswd.pwd" For Random As #1
    > For i = 1 To 10
    > Get #1, User, Password
    > If Text.txtUserNam e = User And Text.txtPasswor d = Password Then
    > LoginSucceeded = True
    > Form_Load.frmDa ta
    > Me.Hide
    > Else: Next i
    > End If
    >
    >
    > Else
    > MsgBox "Invalid Password, try again!", , "Login"
    > txtPassword.Set Focus
    > SendKeys "{Home}+{En d}"
    > End If
    > End Sub
    >
    >
    >
    >
    >[/color]


    Comment

    Working...