|
-
Jan 25th, 2018, 05:52 PM
#1
Thread Starter
Addicted Member
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by OptionBase1
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??
-
Jan 25th, 2018, 05:55 PM
#2
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.
-
Jan 25th, 2018, 05:58 PM
#3
Thread Starter
Addicted Member
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by OptionBase1
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??
-
Jan 25th, 2018, 06:04 PM
#4
Thread Starter
Addicted Member
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by OptionBase1
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
-
Jan 25th, 2018, 06:09 PM
#5
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.
-
Jan 25th, 2018, 06:16 PM
#6
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.
-
Jan 25th, 2018, 06:02 PM
#7
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
-
Jan 25th, 2018, 06:05 PM
#8
Thread Starter
Addicted Member
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by OptionBase1
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?
-
Jan 25th, 2018, 06:12 PM
#9
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by EmilyM1105
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
-
Jan 25th, 2018, 06:20 PM
#10
Thread Starter
Addicted Member
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by OptionBase1
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
-
Jan 25th, 2018, 06:24 PM
#11
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by EmilyM1105
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.
-
Jan 25th, 2018, 06:27 PM
#12
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
-
Jan 25th, 2018, 06:40 PM
#13
Thread Starter
Addicted Member
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by OptionBase1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|