为了账号安全,请及时绑定邮箱和手机立即绑定

为什么以下代码输出的结果是10,求解释~

为什么以下代码输出的结果是10,求解释~

倚天杖 2021-12-02 15:11:24
Private Sub Command1_Click() m = 2.17 n = Len(Str$(m) + Space(5)) Me!Text1 = n End Sub
查看完整描述

2 回答

?
哔哔one

TA贡献1854条经验 获得超8个赞

Private Sub Command1_Click()
Dim n As String, h As String, i As Integer, c As String
n = Trim(Text1.Text)
If Not (IsNumeric(n) And Val(n) > 0 And Int(n) = Val(n)) Then '判断n非数字、非正数、非整数情况
MsgBox "输入数字符n非正整数,请确认退出!", vbOKOnly
Exit Sub
End If
h = Hex(Val(n)) '将n转换成16进制
c = ""
For i = 1 To Len(h)
c = c & Hex2Bin(Mid(h, i, 1))
Next
Print c
End Sub
Function Hex2Bin(ByVal str As String) '自定义函数16进制转换成2进制
Select Case UCase(str)
Case "0": Hex2Bin = "0000"
Case "1": Hex2Bin = "0001"
Case "2": Hex2Bin = "0010"
Case "3": Hex2Bin = "0011"
Case "4": Hex2Bin = "0100"
Case "5": Hex2Bin = "0101"
Case "6": Hex2Bin = "0110"
Case "7": Hex2Bin = "0111"
Case "8": Hex2Bin = "1000"
Case "9": Hex2Bin = "1001"
Case "A": Hex2Bin = "1011"
Case "B": Hex2Bin = "1100"
Case "C": Hex2Bin = "1101"
Case "D": Hex2Bin = "1110"
Case "E": Hex2Bin = "1111"
End Select
End Function



查看完整回答
反对 回复 2021-12-06
?
守着星空守着你

TA贡献1799条经验 获得超8个赞

n=" 2.17 "
注意:2.17前有一个空格,这是str的原因
比如:a="1",则str(a)=" 1",会多出一个空格

查看完整回答
反对 回复 2021-12-06
  • 2 回答
  • 0 关注
  • 316 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信