0

我只是一名 10 年级的编程学生。错误是:Conversion from string "alan" to type 'Boolean' is not valid。我永远无法绕过它。错误在它说的那一行(If firstname = "alan" Or "Alan" Then)。这是代码:

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
4

1 回答 1

1

正确的语法是

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

您需要重复这firstname = <value>两种情况的表达式,但您还需要将 Or 替换为更合适的OrElse

参见Or 与 OrElse

于 2013-10-13T16:03:07.030 回答