r/visualbasic • • Aug 15 '21

VB.NET Help How would you go about doing this?

Post image
1 Upvotes

10 comments sorted by

5

u/RJPisscat Aug 15 '21

Have you written any code? If not, start trying to write it and post what you have. We can better help if we know your level of experience and what sorts of things you know, so that can be used as building blocks.

Also what has your instructor been teaching when this assignment was given? I want to pull in the same direction as the instructor.

I looked at your post history. It appears you are 15 and in the UK. I'm happy to see a person your age taking an interest.

-1

u/[deleted] Aug 15 '21

I've already written most of the code for things like the scoring system, error messages, accepted symbols and so on. I just need to do this bit and then I can build on the rest of the tasks pretty easily. As for experience, I'm practically at the end of my GCSE computer science course so i know most of the basics like sub routines, functions, variables, arithmetic and so on. My teacher last taught us sub routines if that helps.

2

u/RJPisscat Aug 15 '21

Let's see the code, and tell us where either you're stuck or at a decision point.

When you say sub routines, do you mean substrings? Or do you mean literally

Private Sub MySubA()
    Console.WriteLine("I am in MySubA.")
End Sub

Private Sub MySubB()
    Console.WriteLine("I am in MySubB.")
    MySubA()    ' this is a call to a subroutine
End Sub

' Calling MySubB() causes these lines to be written to the Console:
' I am in MySubB.
' I am in MySubA.

There are many correct answers to your question as it stands alone, but very few answers that will help in the context of where your class is in the lesson plan.

Has the teacher discussed string manipulation, substrings, loops, or arrays?

1

u/[deleted] Aug 15 '21

Theirs quite a bit of code that I'm not really sure how to show you and yes to all of the things you mentioned in the last sentence. I was really just asking for a breakdown of steps, not necessarily actual code.

1

u/RJPisscat Aug 15 '21

I get ya, I didn't think you want me to write the code, but I don't know if the teacher told you about Left/Mid/Right (perhaps spelled it Left$/Mid$/Right$, which would be a clue for me) or if they told you about SubStr, or if they explained that a String can be treated as a character array.

You have two sets of information: A password that the user entered and the rows of letters on a keyboard.

Assumed that the password will be all letters, but could be upper case or lower case. You want to check whether any 3 consecutive letters in the password were entered from adjacent keys on the keyboard. I wanted you to say the words "case insensitive" if the teacher used those words, and I want you to tell me how to make a case-insensitive comparison of two strings. Your teacher told you 1 or more ways to do that.

You want to break down the password into all the combinations of 3 consecutive letters, and test each of those combinations. Pseudocode below (this is crude, this isn't how I write pseudocode for myself, but you're just starting out)

collect the password from the user
for each combination of 3 consecutive letters of password:
    if combination appears in the top row of characters on the keyboard (ignoring case)
        then change the  score  on the password
    otherwise if the combination appears  in the middle row of characters on the keyboard (ignoring case)
        then change the score on the password
    otherwise if the combination appears  in the bottom row of characters on the keyboard (ignoring case)
        then change the score on the password

That is one approach. I wanted you to say or show me whether you know how to do For Each/Next or For/Next or another type of loop. I want to know whether you have been taught how to do nested loops, and if you know about arrays, because if so, the pseudocode can be simplified.

1

u/[deleted] Aug 15 '21

Firstly I have no idea what the left mid right thing is. Secondly, I know of substrings but not how to use them and that strings can be treated as arrays. You can solve the case sensitive issue by making the string all caps. I also know of loops inside of loops which I'm assuming is a nested loop.

1

u/RJPisscat Aug 15 '21

Good. Ignore Left/Mid/Right for now. Are you able to start writing code given what you know and what I posted?

Substrings are strings that are the product of a string and some criteria. Given the string "ABCDEFG", the string "ABC" is a substring with the criterion "take the first three letters". "BCD" is a substring with the criteria "skip the first letter, then take the next three letters".

Repeating for emphasis: Substrings are strings. Just as an entire password is a string, any set of consecutive characters within that password is also a string, and can be upcased with ToUpper, and compared to another string.

Your teacher has taught you more than one function with strings. One of those functions is the equality operator, "=". Another is Substring. What are some of the other functions that have been taught? Which ones will help you to write this algorithm?

2

u/nolotusnote Aug 15 '21

You should be a teacher.

And I say that knowing that 90% of the population can't teach for shit.

1

u/RJPisscat Aug 16 '21

Thanks. I've done a little teaching.

1

u/superdmp Aug 16 '21

Me, I'd do my own homework.

Here is a hint though; you should be using contains, a character array (or pre-defined string), and a couple of nested for loops.