-2
我想在VB6中做一個猜謎遊戲。它涉及比較用戶輸入的字母。我已經搜索了它,不幸的是,他們只有最新版本。如何比較VB6中的單個字符?
任何人都可以幫助我比較Visual Basic6.0中的單個字符。因爲,坦率地說,我不知道它。
我想在VB6中做一個猜謎遊戲。它涉及比較用戶輸入的字母。我已經搜索了它,不幸的是,他們只有最新版本。如何比較VB6中的單個字符?
任何人都可以幫助我比較Visual Basic6.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
您還沒有找到任何代碼比較字符串? Google是你的朋友。你到目前爲止嘗試過什麼 - 分享你在VB6 – dbmitch
'Dim MySecretChar As String'中的嘗試,其中只有一個字符串,最簡單的比較可以是'If Text1.Text = MySecretChar Then MsgBox(「good」)'but give更多的洞察力與其他代碼片段,我們只能猜測... –