Results 1 to 40 of 126

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

Hybrid View

  1. #1

    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??

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,631

    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.

  3. #3

    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??

  4. #4

    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

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,631

    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.

  6. #6
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,631

    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.

  7. #7
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,631

    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

  8. #8

    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?

  9. #9
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,631

    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

  10. #10

    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

  11. #11
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,631

    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.

  12. #12
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,631

    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

  13. #13

    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?

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