Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to tell whether a person is a Beatle. Here’s the worksheet: The

ID: 3848363 • Letter: W

Question

Write a program to tell whether a person is a Beatle. Here’s the worksheet:

The user types a name in B1, and clicks the button. If the name if John, Paul, George, or Ringo, the program says that the person is a Beatle:

Otherwise, the program shows “Not a Beatle.”

The program should work for upper- and lowercase characters, and when there are spaces before and/or after the name. For example, “ jOHn “ should be identified as a Beatle.

I cannot get my code to work. When I type in a Beatles name it gives me the message "Not a Beatle"

A 1 First name: George 3 Is that a Beatle? Run

Explanation / Answer

Add the following if-else condition :

If Name.Contains("Beatle") Then

Cells(3,2) = "Thats a Beatle"

Else

Cells(3,2) = " Not a Beatle "

End If

For the first problem(i.e case sensitivity )

Use String.Compare method to comapre 2 strings using False option to ignore case.

Use String.Trim() to remove leading and trailing spaces

Name = Trim(Name)

Cells(3,2) = "Thats a Beatle"

ElseIf String.Compare(Name,"Paul", False) Then  

Cells(3,2) = "Thats a Beatle"

Cells(3,2) = "Thats a Beatle"

Cells(3,2) = "Thats a Beatle"

ElseIf Name.Contains("Beatle") Then

Cells(3,2) = "Thats a Beatle"

Else

Cells(3,2) = " Not a Beatle "

End If

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote