Brent Wheeldon
Brent Wheeldon

Reputation: 3

How do I get around the error: Conversion from string "alan" to type 'Boolean' is not valid

I am just a Yr 10 programming student. The error is: Conversion from string "alan" to type 'Boolean' is not valid. I can never get around it. The error is on the line where it says (If firstname = "alan" Or "Alan" Then). Here is the code:

Module Module1

Sub Main()
    Dim firstname As String
    Console.WriteLine("Hello and welcome to Alan's Computer: Press enter to continue")
    Console.ReadLine()
    Console.WriteLine("Please enter your first name")
    firstname = Console.ReadLine()
    If firstname = "alan" Or "Alan" Then
        Console.WriteLine("Welcome")

    Else
        Console.WriteLine("You may not enter {0}", firstname)
    End If

End Sub

End Module

Upvotes: 0

Views: 61

Answers (1)

Steve
Steve

Reputation: 216303

The correct syntax is

If firstname = "alan" OrElse firstname = "Alan" Then
    Console.WriteLine("Welcome")
Else
    Console.WriteLine("You may not enter {0}", firstname)
End If

You need to repeat the expression firstname = <value> for the two cases, but you need also to replace the Or with the more appropriate OrElse

See Or vs OrElse

Upvotes: 1

Related Questions