|
-
Jan 25th, 2018, 05:24 PM
#1
Thread Starter
Addicted Member
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by OptionBase1
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??
-
Jan 25th, 2018, 05:28 PM
#2
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.
-
Jan 25th, 2018, 05:41 PM
#3
Thread Starter
Addicted Member
Re: Please Help!! Im on a deadline and I cant figure this out!!
 Originally Posted by OptionBase1
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
-
Jan 25th, 2018, 05:45 PM
#4
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.
-
Jan 25th, 2018, 05:50 PM
#5
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.
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
-
Jan 25th, 2018, 05:52 PM
#6
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
#7
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
#8
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
#9
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:02 PM
#10
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
#11
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?
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
|