如何在VB6中比较单个字符?

时间:2016-09-17 17:12:21

标签: vb6

我试图在VB6中进行猜谜游戏。它涉及比较用户输入的字母。我已经搜索过了,不幸的是,他们只有最新版本。

任何人都可以帮我比较Visual Basic6.0中的单个字符。因为,坦白说我根本不知道。

1 个答案:

答案 0 :(得分:0)

Asc和Chr $是要寻找的功能。

Private Sub Form_Load()
    Dim lSecret As Long
    Dim sInput As String
    Dim lAscChar As Long

    'Define a secret character as an ANSI code.
    lSecret = Asc("m")

    Do
        'Let the user input a single character.
        sInput = InputBox("Enter a single character. " & _
            "If more characters are entered, only the first one " & _
            "will be used. To end just click OK without entering text.")
        If Len(sInput) = 0 Then Exit Sub

        'Obtain the first character's ANSI code.
        lAscChar = Asc(sInput)

        'If the user entered the correct secret character, tell her.
        'Otherwise give a hint.
        If lSecret = lAscChar Then
            MsgBox "Great, you are a hero."
            Exit Sub
        ElseIf lSecret < lAscChar Then
            MsgBox "Nope, in the ANSI table, the correct answer is " & _
                "before this one."
        Else
            MsgBox "Nope, in the ANSI table, the correct answer is " & _
                "after this one."
        End If
    Loop
End Sub