'十六进制转换成十进制
Private Function HexToTen(ByVal TheHex As Byte) As Byte
HexToTen = "&H" & TheHex
End Function
'十进制转换成十六进制
Private Function TenToHex(ByVal TheTen As Byte) As Byte
TenToHex = CByte(Hex(TheTen))
End Function
'调用函数
Private Sub Command1_Click()
Dim A As Byte
Dim B As Byte
A = 30
B = HexToTen(A)
MsgBox B
A = TenToHex(B)
MsgBox A
End Sub其中A=数字都行,但是A=字母,比如0A,1E,FF等等 就会出错,请问下是怎么回事,谢谢各位了
Private Function HexToTen(ByVal TheHex As Byte) As Byte
HexToTen = "&H" & TheHex
End Function
'十进制转换成十六进制
Private Function TenToHex(ByVal TheTen As Byte) As Byte
TenToHex = CByte(Hex(TheTen))
End Function
'调用函数
Private Sub Command1_Click()
Dim A As Byte
Dim B As Byte
A = 30
B = HexToTen(A)
MsgBox B
A = TenToHex(B)
MsgBox A
End Sub其中A=数字都行,但是A=字母,比如0A,1E,FF等等 就会出错,请问下是怎么回事,谢谢各位了
解决方案 »
- 如何在RS的结果中查询?
- 在线急等 票据打印与打印机型号问题
- 如何COPY图片中的一部分,这部分图片能够随着鼠标拖动?
- 关于MSHFLEXGRID数据显示问题
- 请教一个非常非常低级的问题
- 我的程序使用了DataEnvironment访问Access数据库。打包安装后运行却报错:未找到提供者,可能未被正确安装。
- 求助 有关DATA控件的问题
- 如何把一个日期字段和combo1.text用sql语句添加到表里?
- 请问各位朋友,本人英语较差,不知哪儿有关于ActiveBar 2.0 的中文使用说明书。
- 挑战性的问题,如何读取图片中的文字
- VBA 做的报表
- 使用vb要求2个客户端视频播放同步,高手进来给点意见
msgbox val("&Hff")
Private Function HexToTen(ByVal TheHex As String) As long
HexToTen = "&H" & TheHex
End Function
'十进制转换成十六进制
Private Function TenToHex(ByVal TheTen As long) As String
TenToHex = Hex(TheTen)
End Function VB里Byte型是用十进制表示的。16进制要用字符串表示,否则会被编译器自动转换成10进制
Private Function HexToTen(ByVal TheHex As string) As long
HexToTen = "&H" & TheHex
End Function
'十进制转换成十六进制
Private Function TenToHex(ByVal TheTen As long) As string
TenToHex = Hex(TheTen) 'TenToHex返回值为字符串类型后,VB会自动转换类型的.
End Function
'调用函数
Private Sub Command1_Click()
Dim A As string '十六进制在VB里用字符串表示,没有相应的数据类型.
Dim B As long '如果你的数值在一个字节以内(十进制255),那才用BYTE类型
A = "200F"
B = HexToTen(A)
MsgBox B
A = TenToHex(B)
MsgBox A
End Sub
Private Function HexToTen(ByVal TheHex As string) As long
HexToTen = "&H" & TheHex
End Function
'十进制转换成十六进制
Private Function TenToHex(ByVal TheTen As long) As string
TenToHex = Hex(TheTen) 'TenToHex返回值为字符串类型后,VB会自动转换类型的.
End Function
'调用函数
Private Sub Command1_Click()
Dim A As string '十六进制在VB里用字符串表示,没有相应的数据类型.
Dim B As long '如果你的数值在一个字节以内(十进制255),那才用BYTE类型
A = "200F"
B = HexToTen(A)
MsgBox B
A = TenToHex(B)
MsgBox A
End Sub
代码格子里原来不能用颜色?
在机内,所有的数组都是二进制。只有给人看的时候,才有所谓十进制、十六进制。在 VB 中,所有的数值类型,接受的都是十进制数。
所谓十六进制,是字符串表达式。所以,从十进制转换成十六进制,是数值型变成字符串,从十六进制到十进制,则是字符串到数值。(当然,你也可以将十进制用字符串来表示。)
但数值型到数值型,是不支持所有十六进制码的,至多是所谓 BCD 码,也就是不包含字母的十六进制数,如你原来的代码所处理的。 '十六进制转换成十进制
Private Function HexToTen(ByVal TheHex As String) As Byte
HexToTen = Val("&H" & TheHex)
End Function
'十进制转换成十六进制
Private Function TenToHex(ByVal TheTen As Byte) As String
TenToHex = Hex(TheTen)
End Function
'调用函数
Private Sub Command1_Click()
Dim A As String
Dim B As Byte
A = "1E"
B = HexToTen(A)
MsgBox B
A = TenToHex(B)
MsgBox A
End Sub