对于家庭作业项目,我试图在单个文本框中输入字符(例如:“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”作为我的输出。
这可以用于通用用途 - 并且更聪明一点:
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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句