对于家庭作业项目,我试图在单个文本框中输入字符(例如:“AbC”没有空格),并在标题标签中输出作为用逗号和空格写出的相应ASCII值。 (例如:65,98,67)
Private Sub cmdCode_Click()
Dim codeInt As Integer
strInput = txtInput.value
codeInt = Asc(strInput)
lblAnswer.Caption = codeInt & ", "
End Sub
我希望结果如下:65,98,67
我没有收到任何错误,只收到“65”作为我的输出。
答案 0 :(得分:2)
这是我的解决方案。它假设输入总是长三(3)个字符:
Private Sub cmdCode_Click()
Dim x As String
Dim y As String
Dim z As String
strInput = txtInput.value
x = Asc(Left(strInput, 1))
y = Asc(Mid(strInput, 2, 1))
z = Asc(Right(strInput, 1))
lblAnswer.Caption = x & ", " & y & ", " & z
End Sub
答案 1 :(得分:1)
这可以用于通用用途 - 而且更聪明一点:
Public Function StrToAscList( _
ByVal Text As String) _
As String
Dim Chars() As Byte
Dim Item As Integer
Dim List As String
Chars() = StrConv(Text, vbFromUnicode)
For Item = LBound(Chars) To UBound(Chars)
If Item > 0 Then List = List & ", "
List = List & CStr(Chars(Item))
Next
StrToAscList = List
End Function
然后:
Me!lblAnswer.Caption = StrToAscList(strInput)