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

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

    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.

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

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,638

    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.

  5. #5

    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

  6. #6

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

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

    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.

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

  9. #9

    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

  10. #10
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,638

    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. #11

    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?

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