Page 3 of 4 FirstFirst 1234 LastLast
Results 81 to 120 of 126

Thread: [RESOLVED] Please Help!! Im on a deadline and I cant figure this out!!

  1. #81

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    So, the intent is that you delegate the checking of the username to the VerifyUsername function, and the checking of the password to the VerifyPassword function. Right now, those functions are doing nothing.

    You said you are in Business Management, so I'll try to relate what a Sub is and what a Function is to running a Business.

    Imagine you are a manager, and you delegate a task to an employee, like "Go clean out the fridge". That is analogous to a Sub. A small task of code that you can just call on to get done whenever it is needed. In fact, you have a Sub in your code right now, the Login Sub.

    Now, imagine you have an employee, and you tell them "Can you print me a sales report from last quarter?" That is analogous to a Function. What is the difference? Well, in this case, you've asked an employee to do something AND give you something in return. If your employee comes back with a Coffee for you, then I'm assuming you would see there would be a problem. So a Function needs to Return a result, and it needs to be the expected type of result.

    Now, in your case, you've been asked to delegate the Login process to a subordinate (the Login Sub), and are told that you need to tell your subordinate to delegate the actual verification of the username and the password to two of their subordinates (the VerifyUsername and VerifyPassword functions).

    What you've coded is that you've delegated the Login process to a subordinate (the Login Sub), and that subordinate is asking two subordinates if they have time do something, they both say Yes, but then your subordinate (the Login Sub) does the checking of the Username and Password itself.

    Does that make sense?
    What you said makes sense but doing it is something i dont get..So I need to take out RETURN TRUE and replace it??

  2. #82

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    This is your code that actually checks to see if the entered username is found in the array:

    Code:
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Exit For
                    End If
                Next

    Essentially, that code should go inside the VerifyUsername function.

    Code:
        Function VerifyUsername(username As String) As Boolean
            
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Exit For
                    End If
                Next
    
        End Function
    But you are going to need to work through a couple issues:

    1. Inside the Function you need to have some code that does a "Return True" if the username is found, and a "Return False" if the username isn't found. There are several was to write the logic to do this.
    2. Your code to check for the password relies on knowing the value of userIndex. So you will have to do something with the userIndex variable to make it so that this value is accessible in both the VerifyUsername and VerifyPassword function (Hint: look at how blnLoggedIn is initialized).
    So do I need to just delete it out of that area and copy and paste it in the function area. Or does it need to be in both places??

  3. #83
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    It should only be in the VerifyUsername function. But as I indicated, you need to add additional code to it to get it to work properly. If you just move it and leave the code as is your program won't work properly.

    In the end, the Login Sub should only look something like this:

    Code:
        Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) AndAlso VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    I hope you can see from that that you are relying on the VerifyUsername and VerifyPassword functions to actually do the checking of the username and password.

    Edit: you should be using an AndAlso in your If statement, since if the username isn't found there is no need to check the password.
    Last edited by OptionBase1; Jan 25th, 2018 at 05:33 PM.

  4. #84

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    It should only be in the VerifyUsername function. But as I indicated, you need to add additional code to it to get it to work properly. If you just move it and leave the code as is your program won't work properly.

    In the end, the Login Sub should only look something like this:

    Code:
        Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) AndAlso VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    I hope you can see from that that you are relying on the VerifyUsername and VerifyPassword functions to actually do the checking of the username and password.

    Edit: you should be using an AndAlso in your If statement, since if the username isn't found there is no need to check the password.
    ok so should i look like this?

    Code:
    Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) And VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    
    Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Exit For
                    End If
                Next
    
              
        End Function
    
        Function VerifyPassword(password As String) As Boolean
            Return True
            'If the passwords match, Return True, otherwise Return False
        End Function
    
    End Module

  5. #85
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    You also need to put the password verification code that was in the Login Sub into the VerifyPassword Function.

    And as I mentioned above, you need to add additional code in VerifyUsername that does a "Return True" if the username is found. So, if you look at your code, do you see a place where you are already determining if the username is found? If so, that is where the "Return True" statement belongs.

    And here's a hint: When a function returns a value, any loops that are in progress automatically get terminated and the function exits.

  6. #86

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    You also need to put the password verification code that was in the Login Sub into the VerifyPassword Function.

    And as I mentioned above, you need to add additional code in VerifyUsername that does a "Return True" if the username is found. So, if you look at your code, do you see a place where you are already determining if the username is found? If so, that is where the "Return True" statement belongs.

    And here's a hint: When a function returns a value, any loops that are in progress automatically get terminated and the function exits.
    ok so like this?

    Code:
    Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) And VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    
    Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Exit For
                    End If
                Next
    
              
        End Function
    
        Function VerifyPassword(password As String) As Boolean
           If arrPasswords(userIndex) = password Then 
    
        End Function
    
    End Module

  7. #87

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    You also need to put the password verification code that was in the Login Sub into the VerifyPassword Function.

    And as I mentioned above, you need to add additional code in VerifyUsername that does a "Return True" if the username is found. So, if you look at your code, do you see a place where you are already determining if the username is found? If so, that is where the "Return True" statement belongs.

    And here's a hint: When a function returns a value, any loops that are in progress automatically get terminated and the function exits.
    Thats what I dont understand though..How do i connect the two functions?? If I put anything that has to do with the password in the username function i get an error??

  8. #88
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Don't even bother trying to run the code yet, you're several steps away from the program compiling. Just keep posting your code as it is currently.

    You need to get the VerifyUsername function working before moving to the VerifyPassword function. I'll repeat myself from above:

    And as I mentioned above, you need to add additional code in VerifyUsername that does a "Return True" if the username is found. So, if you look at your code, do you see a place where you are already determining if the username is found? If so, that is where the "Return True" statement belongs.

    And here's a hint: When a function returns a value, any loops that are in progress automatically get terminated and the function exits.

  9. #89

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    Don't even bother trying to run the code yet, you're several steps away from the program compiling. Just keep posting your code as it is currently.

    You need to get the VerifyUsername function working before moving to the VerifyPassword function. I'll repeat myself from above:

    And as I mentioned above, you need to add additional code in VerifyUsername that does a "Return True" if the username is found. So, if you look at your code, do you see a place where you are already determining if the username is found? If so, that is where the "Return True" statement belongs.

    And here's a hint: When a function returns a value, any loops that are in progress automatically get terminated and the function exits.
    This part?? blnLoggedIn = True??

  10. #90
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    No, somewhere in the code below.

    Code:
        Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Exit For
                    End If
                Next
              
        End Function

  11. #91

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    Don't even bother trying to run the code yet, you're several steps away from the program compiling. Just keep posting your code as it is currently.

    You need to get the VerifyUsername function working before moving to the VerifyPassword function. I'll repeat myself from above:

    And as I mentioned above, you need to add additional code in VerifyUsername that does a "Return True" if the username is found. So, if you look at your code, do you see a place where you are already determining if the username is found? If so, that is where the "Return True" statement belongs.

    And here's a hint: When a function returns a value, any loops that are in progress automatically get terminated and the function exits.
    So is this right?

    Code:
    Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) And VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    
    Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Exit For
                    End If
                Next
           Return True
            blnLoggedIn = True
    
    
              
        End Function
    
        Function VerifyPassword(password As String) As Boolean
           If arrPasswords(userIndex) = password Then 
    
        End Function
    
    End Module

  12. #92

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    No, somewhere in the code below.

    Code:
        Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Exit For
                    End If
                Next
              
        End Function
    Oh ok so is it userindex = loopindex?

  13. #93
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    (In response to your post two above this one)

    Ok, so lets work through a test of that code with valid usernames of {"Admin, Clerk, Manager"}

    I enter a username of "OptionBase1"

    The function receives a username of "OptionBase1".
    The For loop starts.
    It checks if "Admin" is equal to "OptionBase1", and it isn't
    It checks if "Clerk" is equal to "OptionBase1", and it isn't
    It checks if "Manager" is equal to "OptionBase1", and it isn't
    The For loop is done checking through all usernames
    Return true is executed, indicating that the username was found

    So, where you put Return True produced an incorrect result.

  14. #94
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by EmilyM1105 View Post
    Oh ok so is it userindex = loopindex?
    After that line, yes. We want the line userIndex = loopIndex to remain, since we will be relying on that value when we get to the VerifyPassword Function.

    Code:
        Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Return True
                    End If
                Next
              
        End Function

  15. #95
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    So now, we need to do something to Return False in the case that the username is not found. As I mentioned above, when a Return statement executes, any loops are terminated and the function is exited. So with that being said, let me ask you a question. Given the following code, would the message box show up:

    1. Every time the function is called with any username passed
    2. Only when the function is called and an valid username is passed
    3. Only when the function is called and an invalid username is passed

    Code:
        Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Return True
                    End If
                Next
             Messagebox.Show("Hi!!!")          
    
        End Function
    Last edited by OptionBase1; Jan 25th, 2018 at 06:21 PM.

  16. #96

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    After that line, yes. We want the line userIndex = loopIndex to remain, since we will be relying on that value when we get to the VerifyPassword Function.

    Code:
        Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Return True
                    End If
                Next
              
        End Function
    ok so what should be after the Next part?

    Code:
    Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Return True
                    End If
                Next
              
        End Function

  17. #97
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by EmilyM1105 View Post
    ok so what should be after the Next part?

    Code:
    Function VerifyUsername(username As String) As Boolean
           
                Dim userIndex As Integer
                For loopIndex = 0 To arrUsernames.Length - 1
                    If arrUsernames(loopIndex) = username Then
                        userIndex = loopIndex
                        Return True
                    End If
                Next
              Return False
        End Function
    Yes, after the Next statement is where Return False should go. Because that line will only ever be executed if the For Loop completes and doesn't find a valid username, since when a valid username is found, Return True is executed and the Function is immediately terminated.

  18. #98
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Ok, now, before we go further, we need to address the userIndex variable. Right now, it is being created inside of the VerifyUsername function. But the code you are using to check the password relies on that value being accessible inside the VerifyPassword function as well. So, you've got several examples of variables that are declared in a way that make them accessible in the entire Main Module, which is what is needed for userIndex.

    Does that help you to figure out where the following line of code should be moved to?

    Code:
    Dim userIndex As Integer

  19. #99

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    Ok, now, before we go further, we need to address the userIndex variable. Right now, it is being created inside of the VerifyUsername function. But the code you are using to check the password relies on that value being accessible inside the VerifyPassword function as well. So, you've got several examples of variables that are declared in a way that make them accessible in the entire Main Module, which is what is needed for userIndex.

    Does that help you to figure out where the following line of code should be moved to?

    Code:
    Dim userIndex As Integer
    In the password section?

  20. #100
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    No, because then it wouldn't be available in the VerifyUsername function. And you might think, then what if we put:

    Code:
    Dim userIndex As Integer
    in both the VerifyUsername and VerifyPassword functions? The result is there will be two different variables, and the value will not "transfer" from one function to the other.

    Hint: You are able to access the arrUsernames() array anywhere in the Main Module. Why is that?

  21. #101

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    No, because then it wouldn't be available in the VerifyUsername function. And you might think, then what if we put:

    Code:
    Dim userIndex As Integer
    in both the VerifyUsername and VerifyPassword functions? The result is there will be two different variables, and the value will not "transfer" from one function to the other.

    Hint: You are able to access the arrUsernames() array anywhere in the Main Module. Why is that?
    Because of this?

    Code:
    If arrUsernames(loopIndex) = username

  22. #102
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    No. Just so it's clear, I'm referring the entirety of your code in Module Main right now. The whole thing from:

    Code:
    Module Main
    to

    Code:
    End Module
    Where is arrUsernames() initialized (or created)?

  23. #103

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    No. Just so it's clear, I'm referring the entirety of your code in Module Main right now. The whole thing from:

    Code:
    Module Main
    to

    Code:
    End Module
    Where is arrUsernames() initialized (or created)?
    Here?

    Code:
     Dim arrUsernames() As String = {"Admin, Clerk, Manager"}
        Dim arrPasswords() As String = {"P@ssword, pa$$word, and passw0rd"}

  24. #104
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Right, and you'll see that those lines of code appear right after the "Module Main" line. They are declared above and outside of any Sub's, or Function's. When variables are declared like this, they are commonly referred to as "Module Level" variables. Which means they are available to be accessed by any Subs or Functions inside that Module.

    So, we want to make userIndex a Module Level variable.

    So, the first few lines Module Main should now look like this:

    Code:
    Module Main
        Friend blnLoggedIn As Boolean
        Dim arrUsernames() As String = {"Admin, Clerk, Manager"}
        Dim arrPasswords() As String = {"P@ssword, pa$$word, and passw0rd"}
        Dim userIndex As Integer
    and you want to make sure to remove:

    Code:
        Dim userIndex As Integer
    from the VerifyUsername Function.

    So now the VerifyUsername Function should be coded properly and the VerifyPassword Function is ready to complete, which should be straightforward. Can you post what your Module Main code looks like now?

  25. #105

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    Right, and you'll see that those lines of code appear right after the "Module Main" line. They are declared above and outside of any Sub's, or Function's. When variables are declared like this, they are commonly referred to as "Module Level" variables. Which means they are available to be accessed by any Subs or Functions inside that Module.

    So, we want to make userIndex a Module Level variable.

    So, the first few lines Module Main should now look like this:

    Code:
    Module Main
        Friend blnLoggedIn As Boolean
        Dim arrUsernames() As String = {"Admin, Clerk, Manager"}
        Dim arrPasswords() As String = {"P@ssword, pa$$word, and passw0rd"}
        Dim userIndex As Integer
    and you want to make sure to remove:

    Code:
        Dim userIndex As Integer
    from the VerifyUsername Function.

    So now the VerifyUsername Function should be coded properly and the VerifyPassword Function is ready to complete, which should be straightforward. Can you post what your Module Main code looks like now?
    ok so this is what i have..Is the password function right?

    Code:
    Module Main
        Friend blnLoggedIn As Boolean
        Dim arrUsernames() As String = {"Admin, Clerk, Manager"}
        Dim arrPasswords() As String = {"P@ssword, pa$$word, and passw0rd"}
        Dim userIndex As Integer
    
        Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) And VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    
        Function VerifyUsername(username As String) As Boolean
            For loopIndex = 0 To arrUsernames.Length - 1
                If arrUsernames(loopIndex) = username Then
                    userIndex = loopIndex
                    Return True
                    Exit For
                End If
            Next
            Return False
        End Function
    
        Function VerifyPassword(password As String) As Boolean
            If arrPasswords(userIndex) = password Then
                Return True
            End If

  26. #106
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Yes, your VerifyPassword Function looks good if the password is valid. But remember, if the password isn't valid then there needs to be a "Return False" statement that is executed.

  27. #107

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    Yes, your VerifyPassword Function looks good if the password is valid. But remember, if the password isn't valid then there needs to be a "Return False" statement that is executed.
    When I try to use next after Return True it keeps replacing my "Next" with "On error resume next". Do I even use Next for that?

  28. #108
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    No.

    As a hint, this was your old password checking code:

    Code:
                'Check for password match
                If arrPasswords(userIndex) = password Then
                    blnLoggedIn = True
                Else
                    MessageBox.Show(“Incorrect password.”)
                End If
    We've replaced

    Code:
    blnLoggedIn = True
    with

    Code:
    Return True

  29. #109

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    No.

    As a hint, this was your old password checking code:

    Code:
                'Check for password match
                If arrPasswords(userIndex) = password Then
                    blnLoggedIn = True
                Else
                    MessageBox.Show(“Incorrect password.”)
                End If
    We've replaced

    Code:
    blnLoggedIn = True
    with

    Code:
    Return True
    Ok so this is what i have

    Code:
    Function VerifyPassword(password As String) As Boolean
            'Check for password match
            If arrPasswords(userIndex) = password Then
                Return True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
        End Function
    
    End Module
    But it has the error message still saying its not showing a return on all code paths??

  30. #110

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    No.

    As a hint, this was your old password checking code:

    Code:
                'Check for password match
                If arrPasswords(userIndex) = password Then
                    blnLoggedIn = True
                Else
                    MessageBox.Show(“Incorrect password.”)
                End If
    We've replaced

    Code:
    blnLoggedIn = True
    with

    Code:
    Return True
    Do I do this?

    Code:
    Function VerifyPassword(password As String) As Boolean
            'Check for password match
            If arrPasswords(userIndex) = password Then
                Return True
            Else
                Return False
                MessageBox.Show(“Incorrect password.”)
            End If
        End Function
    
    End Module

  31. #111
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Right. So, if the password isn't valid, we need a "Return False" statement executed, but we don't want the MessageBox displayed.

    In your code above, the MessageBox will never actually show because Return False will terminate the VerifyPassword function, but that line should be removed for clarity.

  32. #112
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Ok, I think there are two very minor changes that should be made at this point.

    In your If statement in Sub Login, you should replace the "And" with "AndAlso".

    When you use "And" in an If statement, both comparisons are evaluated even when the first comparison evaluates to False. In this case, if you keep "And" as is, the VerifyPassword function will be called even when VerifyUsername returns False, which indicates that the username isn't found, which I'm sure you would agree is useless.

    When you use "AndAlso" in an If statement, the second comparison is only evaluated if the first comparison evaluates to True. In this case, that means that the VerifyPassword function is only called when VerifyUsername returns True, which is exactly what you want.

    The other change is that in the VerifyUsername function, the "Exit For" line can be removed, since "Return True" automatically exits the For statement and exits the function.

    Once you make those changes, can you post your current Module Main code again?

  33. #113

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    So do i just have to take out the Message box like this? This is my full code:


    Code:
    Module Main
        Friend blnLoggedIn As Boolean
        Dim arrUsernames() As String = {"Admin, Clerk, Manager"}
        Dim arrPasswords() As String = {"P@ssword, pa$$word, and passw0rd"}
        Dim userIndex As Integer
    
        Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) And VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    
        Function VerifyUsername(username As String) As Boolean
            For loopIndex = 0 To arrUsernames.Length - 1
                If arrUsernames(loopIndex) = username Then
                    userIndex = loopIndex
                    Return True
                    Exit For
                End If
            Next
            Return False
        End Function
    
        Function VerifyPassword(password As String) As Boolean
            'Check for password match
            If arrPasswords(userIndex) = password Then
                Return True
            Else
                Return False
            End If
        End Function
    
    End Module

  34. #114
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by EmilyM1105 View Post
    So do i just have to take out the Message box like this? This is my full code:


    Code:
    Module Main
        Friend blnLoggedIn As Boolean
        Dim arrUsernames() As String = {"Admin, Clerk, Manager"}
        Dim arrPasswords() As String = {"P@ssword, pa$$word, and passw0rd"}
        Dim userIndex As Integer
    
        Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) AndAlso VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    
        Function VerifyUsername(username As String) As Boolean
            For loopIndex = 0 To arrUsernames.Length - 1
                If arrUsernames(loopIndex) = username Then
                    userIndex = loopIndex
                    Return True
                    Exit For  <-  For clarity, you should remove this line, it is not needed
                End If
            Next
            Return False
        End Function
    
        Function VerifyPassword(password As String) As Boolean
            'Check for password match
            If arrPasswords(userIndex) = password Then
                Return True
            Else
                Return False
            End If
        End Function
    
    End Module
    See in bold the changes I outlined in my last post above.

    Once you make those changes, your program should work exactly as the assignment outlined it to work.

  35. #115

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    OK SO THIS IS RIGHT??!

    Code:
    Module Main
        Friend blnLoggedIn As Boolean
        Dim arrUsernames() As String = {"Admin, Clerk, Manager"}
        Dim arrPasswords() As String = {"P@ssword, pa$$word, and passw0rd"}
        Dim userIndex As Integer
    
        Sub Login(username As String, password As String)
            blnLoggedIn = False
            If VerifyUsername(username) And VerifyPassword(password) Then
                blnLoggedIn = True
            Else
                MessageBox.Show(“Incorrect password.”)
            End If
    
        End Sub
    
        Function VerifyUsername(username As String) As Boolean
            For loopIndex = 0 To arrUsernames.Length - 1
                If arrUsernames(loopIndex) = username Then
                    userIndex = loopIndex
                    Return True
                End If
            Next
            Return False
        End Function
    
        Function VerifyPassword(password As String) As Boolean
            'Check for password match
            If arrPasswords(userIndex) = password Then
                Return True
            Else
                Return False
            End If
        End Function
    
    End Module

  36. #116

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Quote Originally Posted by OptionBase1 View Post
    See in bold the changes I outlined in my last post above.

    Once you make those changes, your program should work exactly as the assignment outlined it to work.
    And my Login Form??

    Code:
    Public Class LoginForm
        Private Sub Label1_Click(sender As Object, e As EventArgs) Handles lblUsername.Click, btnLogin.Click
            Login(txtUsername.Text, txtPassword.Text)
            If Main.blnLoggedIn Then
                MessageBox.Show(“Thank you for logging in, “ & txtUsername.Text, “Logged In.”)
                Me.Close()
            End If
    
        End Sub
    
        Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
            Application.Exit()
        End Sub
    End Class

  37. #117
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    Yeah, that should compile and run (assuming you've left the code in your Form unchanged) and you should be able to verify usernames and passwords.

    Edit: Well, one last thing. Right now your Form code triggers a Login attempt when you click lblUsername or when you click btnLogin. You can see at the end of your "Private Sub Label1_Click(...." statement, it says
    Code:
    Handles lblUsername.Click, btnLogin.Click
    Assuming that is not intentional, your instructor might question why you have that Sub set to run when lblUsername is clicked, and might dock you for it.

    If it is not intentional, you should change:

    Code:
    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles lblUsername.Click, btnLogin.Click
    to:

    Code:
    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
    so that the sub name is consistent with the Control name and action, and so that it only runs when btnLogin is clicked.
    Last edited by OptionBase1; Jan 25th, 2018 at 07:46 PM.

  38. #118

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    ok so I have this for my loginform:

    Code:
    Public Class LoginForm
        Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
            Login(txtUsername.Text, txtPassword.Text)
            If Main.blnLoggedIn Then
                MessageBox.Show(“Thank you for logging in, “ & txtUsername.Text, “Logged In.”)
                Me.Close()
            End If
    
        End Sub
    
        Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
            Application.Exit()
        End Sub
    End Class

  39. #119
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    So if you try to compile and run it now, does it work? (It should!)

  40. #120

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Please Help!! Im on a deadline and I cant figure this out!!

    It tells me incorrect password even if i put in the right password?? Shouldnt it say thank you for logging in?

Page 3 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width