我的办法是这样的:
a=right("0000" & "6a2",4)
b=right("0000" & "5b",4)
c="&H" & a & b
虽然笨了点儿,但这方法比较可靠。
例如坐标为x,y
a=right("0000" & hex(x),4)
b=right("0000" & hex(y),4)
c="&H" & a & b
就行了,
对于x,y的提取,用len判断长度,然后mid方式安位取数,去掉第一位和最后一位括号,然后判断是否为逗号,是则将逗号前面的数据赋值给x,后面的赋值给y,然后继续用我那方法。嘿嘿
Private Sub Command1_Click()
Dim h As Integer
Dim l As Integer
h = &H123
l = &H456
Print Hex(MAKEPARAM(h, l))
End Sub
Private Function MAKEPARAM(ByVal h As Integer, ByVal l As Integer) As Long
Dim R As String
R = String(4 - Hex(h), "0") & Hex(h) & String(4 - Hex(l), "0") & Hex(l)
MAKEPARAM = CDec("&h" & R)
End Function
'必须用len,VB6.0里不支持任何移位运算,到了.NET才有这样的运算类型
这位同志,回答之前先说下,按你上面的数据,是一个long型的
也就是4字节有,你说的只是前二字节和后两字节,按位算的话是,前16位,后16位
Function MYFun(L2Byte As Integer, R2Byte As Integer) As Long
MYFun = Val("&H" & Hex(L2Byte) & "0000") Or R2Byte
End Function
好了,已经通过 VB6
下面是我试的,两种方法CopyMemory 才算真正的,哈
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, _
ByVal Length As Long)
Function MYFun(L2Byte As Integer, R2Byte As Integer) As Long
MYFun = Val("&H" & Hex(L2Byte) & "0000") Or R2Byte
End Function
Function MYFun2(L2Byte As Integer, R2Byte As Integer) As Long
Dim s As Long
CopyMemory s, R2Byte, 2
CopyMemory ByVal VarPtr(s) + 2, L2Byte, 2
MYFun2 = s
End Function
Private Sub Form_Paint()
Me.Print Hex(MYFun(&H10, &H22)), Hex(MYFun2(&H10, &H22))
End Sub