-
Re: Please Help!! Im on a deadline and I cant figure this out!!
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
Poor examples? I was basing my assistance directly on the code posted by the user. In a case like this, I'm not going to provide code at a level that I would use were it me writing the program, that doesn't accomplish anything other than copy/paste and nothing is learned. I was providing assistance that was in-line with the posters abilities, in my opinion.
Dont listen to that comment hes just mad thats hes the poor example on this thread!! Hes the one coming at people rude and trying to blame someone else. SORRY NOT SORRY!! You helped me based on my skill level and now I understand how to make it work!! Thank you again!
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
You'd likely find this site a useful reference. It's one we often recommend when starting out:
https://www.homeandlearn.co.uk/NET/vbNet_video.html
Whatever course you are in is not giving you much of a foundation in coding based on some of the questions you've asked. That's not all that unusual around here. I'd say that it reflects poorly on the state of teaching of programming languages, but it's not safe to say that. After all, if your teacher was doing a great job, would you even be here? Therefore, those people who come here may be coming from less quality courses. On the other hand, it really comes down to whether you want to learn programming, or not, and that's not something you likely know when you are starting out. Many of us, like myself, never took a course in computers of any sort, so we only learned at whatever pace and in whatever way we wanted to. When you are in a class, you go at the pace of the class....and in the direction the class takes you, which may not be great.
As I said before, debugging is a skill I think should be covered second (right after data types), yet it is often completely ignored, as it was for your class. On the other hand, we get questions ranging from "nobody knows the answer" to super easy. It's often hard to know how to answer because we don't know what lever the person is coming from, especially when it is a question from class work. Is it a good class? Did it cover X? Always hard to say.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
Did you read the first post in this thread? The directions provided in the first post specifically state to use arrays. How exactly do think putting the data in a ListView solves anything here? All your post will do is confuse the poster even more since the code you posted accomplishes exactly 0 towards the end goal of the program.
well your a real sunshine...
what does this do then (I highlighted it Blue, just for the sunshines of this world)
Code:
Public Sub lvwAddItem(ByVal lvw As ListView, ByVal ParamArray Text() As String)
With lvw.Items
.Add(New ListViewItem(Text))
End With
End Sub
regards
Chris
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
ChrisE
well your a real sunshine...
what does this do then (I highlighted it Blue, just for the sunshines of this world)
Code:
Public Sub lvwAddItem(ByVal lvw As ListView, ByVal ParamArray Text() As String)
With lvw.Items
.Add(New ListViewItem(Text))
End With
End Sub
regards
Chris
I would be happy to apologize profusely to you if you can point out any post that suggests that using a ListView accomplishes anything regarding the problem posted.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
You two bickering and sniping isn't really helping anyone. I can't figure out what actually happened in the thread because of it.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Or anyone else bickering and sniping in this thread.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
Shaggy Hiker
You'd likely find this site a useful reference. It's one we often recommend when starting out:
https://www.homeandlearn.co.uk/NET/vbNet_video.html
Whatever course you are in is not giving you much of a foundation in coding based on some of the questions you've asked. That's not all that unusual around here. I'd say that it reflects poorly on the state of teaching of programming languages, but it's not safe to say that. After all, if your teacher was doing a great job, would you even be here? Therefore, those people who come here may be coming from less quality courses. On the other hand, it really comes down to whether you want to learn programming, or not, and that's not something you likely know when you are starting out. Many of us, like myself, never took a course in computers of any sort, so we only learned at whatever pace and in whatever way we wanted to. When you are in a class, you go at the pace of the class....and in the direction the class takes you, which may not be great.
As I said before, debugging is a skill I think should be covered second (right after data types), yet it is often completely ignored, as it was for your class. On the other hand, we get questions ranging from "nobody knows the answer" to super easy. It's often hard to know how to answer because we don't know what lever the person is coming from, especially when it is a question from class work. Is it a good class? Did it cover X? Always hard to say.
Yea Im getting my Bachelors in business management and Visual Basic is one of my electives. So I pretty much got thrown into it plus its online course so I really have to figure it out on my own
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Oh yeah, "X for Non-X Majors", that's not a category that serves the best for anybody, no matter what X is.
I got thinking about the question, after I wrote that. I can honestly say that I have no idea how I learned to program. I have NO memory of learning any part of it. No light bulb moments. No dawning of comprehension. Nothing like that at all. I started when I was pretty young, and must have learned the basics of methods, loops, conditional statements, and variables. I then didn't do any more for a few years, then spent a few months in HS working on a program with some friends, till it started killing my grades, at which point we all stopped. I don't know why I thought I could do that, but I must have felt good enough about programming to undertake writing a program, cause I wasn't learning coding at that time. I then didn't touch it again until after grad school, when I needed to do something for a job....and now it IS my job.
So, as far as my memory is concerned, I never learned it, I just always knew it. That certainly can't be right, but just as certainly makes it harder for me to answer certain types of questions. I don't remember not knowing. However, I do remember not knowing RegEx, and JavaScript (though that is still just programming), so I would say that a tutorial to have at hand is useful. I don't advocate learning any language from just one source. When I was learning C++, I had two books (no internet). One was a good, general, instruction book, while the other was also pretty good, but not quite AS good. However, both presented the same things in different ways. So, I'd read it in one book, then read it in the other book, and the different flavors would blend to create a better understanding than either one was able to do on its own.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
I could argue expecting someone to show proficiency in programming in one semester is foolhardy.
Everything in programming builds on something else. Starting with a language like LOGO is probably "best", because it gets the student used to thinking in terms of telling the computer discrete statements, one at a time, and seeing how small changes can result in complex new behavior.
LOGO doesn't have a concept of variables, if I recall. That's a good next step, but I don't know a language that just has simple statements and variables. If you know variables you usually learn flow control along with it: only While loops and If statements are necessary, but For loops are a good syntax sugar as well. This is about the level of TI-BASIC, which is actually the first language I ever used.
From there, arrays are their own topic. What they are. How they're used. Their relationship with loops. How to add, how to insert, how to remove. Sorting. Shuffling. None of this makes sense without all of the other topics. All of it is required to have anything approaching proficiency.
What next, methods? It's hard to write a program all in one method. Arguably you should learn them before arrays, but arrays being a variable-like thing makes this questionable. Return values. Parameters. We can't talk about ByRef yet, but there it is.
After methods, classes. And I guess structs. Somehow we have to talk about inheritance, polymorphism, sneak in interfaces... it's hard to talk about methods before these but methods make no sense without them? That's why non-OO languages like Pascal seem like good stepping stones. (Incidentally, that was my second language.)
Now you need events. They're sort of fancy methods, so it's not a big discussion.
Then, FINALLY, you have the information you need to start doing meaningful things with Windows Forms.
This is very much like math subjects. Starting with a VB WinForms project is like starting a mathematics class with Trig identities, saying, "Just roll with this, you'll learn it all later." If you've got the touch, sure, you'll probably work it all out. I don't think most of these "Programming for <major that needs 1 elective>" courses should assume they're talking to prodigal programmers.
I taught myself programming. My first contact was maybe in 1998. I don't think I wrote a significant program until 2000 or so. I certainly didn't finish any projects until then. It is a long, slow, laborious process. Faster now, due to the internet and better languages, but still not something you can cram.
But VB is "the easy language" so they just buy a curriculum and tell the students to do it, because they care about as much for the students' well-being as the students care about being VB developers. You can't do squat in VB until you've made it through half a book's content. LOGO takes 1 page for a kid to start poking and speculating and trying new things.
Niche, focused topics would make a heck of a lot more sense for business major programming. Excel formulas. Excel VBA. Python financial libraries. These are things that represent an edge. "Making a vending machine in VB .NET" is not the way to show them this will be an important skill.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
This was just one step to my project thats going to be graded. I have 4 more to go so Im hoping I can get through them okay. Im not very good at this I will admit
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
I'm glad it works.
Well now Im super confused.. My instructor returned my assignment without grading it..He said:
Thank you for your recent project submission. Unfortunately, I cannot grade your work at this time because you did not code the VerifyUsername and VerifyPassword Functions properly in your program.
I dont know what to do at this point..the program works so how else am i supposed to code that?
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Help me out a little because this thread got a little muddied.
- What is your actual assignment?
- What, if any, is the exact example code that came with it?
- What is the exact code you submitted?
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
Sitten Spynne
Help me out a little because this thread got a little muddied.
- What is your actual assignment?
- What, if any, is the exact example code that came with it?
- What is the exact code you submitted?
My exact assignment is the very first post on this thread
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
Sitten Spynne
Help me out a little because this thread got a little muddied.
- What is your actual assignment?
- What, if any, is the exact example code that came with it?
- What is the exact code you submitted?
It looks different then it originally did on this thread because Ive moved on to a different part of the assignment now..My only issue at this point is that my instructor returned it without grading because he said that my functions arent coded properly..The program works so im not sure how else to code it
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
EmilyM1105
Well now Im super confused.. My instructor returned my assignment without grading it..He said:
Thank you for your recent project submission. Unfortunately, I cannot grade your work at this time because you did not code the VerifyUsername and VerifyPassword Functions properly in your program.
I dont know what to do at this point..the program works so how else am i supposed to code that?
I pointed this out in two separate posts:
Quote:
Originally Posted by
OptionBase1
You have defined the two functions listed above, but your code to actually check the username and the password is in the Login Sub.
Quote:
Originally Posted by
OptionBase1
Your code was close enough to demonstrate that you know most of what you are intended to do. You still don't have any of the code for checking the username and password inside of the actual VerifyUsername and VerifyPassword functions, and you're never calling the Login method, which I and others pointed out.
If you make the bolded changes below your program should work, but you likely won't get full credit due to not implementing the specified functions completely.
There are many ways to get a program to produce the correct results, but not all of them are "right" when you are given strict guidelines as to how your program should be written. Your instructor is right. You disappeared for several days and then came back pretty worked up about a deadline, so helping you get your code to work as you had coded it was really the only option at that point. I'll make a follow-up post in a second.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
In your original post
Quote:
Using what you know about search arrays, implement the VerifyUsername and VerifyPassword functions. They should return true if the username or password is found in the arrUsernames or arrPasswords array, respectively.
Your code doesn't do that, all your functions do is Return True.
Code:
Function VerifyUsername(username As String) As Boolean
'If the username is found, Return True, otherwise Return False
Return True
End Function
Function VerifyPassword(password As String) As Boolean
'If the passwords match, Return True, otherwise Return False
Return True
End Function
You put the code for verifying the UserName and Password in the LogIn procedure.
Quote:
Thank you for your recent project submission. Unfortunately, I cannot grade your work at this time because you did not code the VerifyUsername and VerifyPassword Functions properly in your program.
It seem your instructor wants you to move your verification code to those functions.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
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?
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
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. The "As Boolean" at the end of the Funcion declaration means that the function will return a Boolean value, so it has to return True or False.
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).
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
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??
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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??
-
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.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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
-
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.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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??
-
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.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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??
-
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
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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?
-
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.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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
-
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
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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.
-
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
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
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?
-
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?
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
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
-
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:
to
Where is arrUsernames() initialized (or created)?
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
No. Just so it's clear, I'm referring the entirety of your code in Module Main right now. The whole thing from:
to
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"}
-
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?
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
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
-
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.
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
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?
-
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
with
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
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
with
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??
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
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
with
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
-
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.
-
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?
-
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
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
EmilyM1105
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.
-
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
-
Re: Please Help!! Im on a deadline and I cant figure this out!!
Quote:
Originally Posted by
OptionBase1
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
-
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.
-
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
-
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!)
-
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?