I'm taking Intro. to Programming this semester and we are using VB. I'm stumped on a part of my coding. When I click the "process" button, I need a Message to display "You are in line 3. Your pin number is *."
The pin number must be made of first letter of first name, first letter of middle name, first letter of last name, and first 2 digits of id.
This is how I've started, but I know I'm leaving something off. Entries should not be case sensitive. When I type just a letter ex. "a" in last name it gives me the result ex. "line 1", but when I type a full last name ex. "allen" it gives me nothing.
'Use if then to determine which line message
If strLastName.Substring(0) = "a-c" Then
strMessage = "line 1."
ElseIf strLastName.Substring(0) = "g-l" Then
strMessage = "line 2."
ElseIf strLastName.Substring(0) = "m-q" Then
strMessage = "line 3."
ElseIf strLastName.Substring(0) = " r-v" Then
strMessage = "line 4."
ElseIf strLastName.Substring(0) = "w-z" Then
strMessage = "line 5."
End If
MessageBox.Show("You are in " & strMessage & " "Your pin number is " & )
End Sub
If
doesnt work like that.strLastName.Substring(0) = "a-c"
will be testing if the first character equals "a-c" which it never can be. Not even "a" should work. This likely wont work on foreign character sets, but is a compact form of what you are trying to do:Using a range as the code in the questions seems to want, can work but specifying each character is better. Alternatively, you could test if the first char is in a string representing a range:
Long story short: convert to ASCII, then use Select-Case ranges.
String.Substring when called with only one integer parameter means, take everything from the index passed to the end of the string. So, if the
strLastName
is "abc" withstrLastName.Substring(0)
you get back "abc"To get the character at the first position in strLastName you write
Now to check in which line (?) you are, you could write something like this
Of course the arrays above are defined with arbitrary elements and with only the lower case versions of the letters. But this is just for example.