1.long数据类型相关函数,以下函数来自网络,具体来源网站未做记录,仅做了简单测试。
'将16进制字符串转换为Long整型数据 Public Function HEX_to_DEC(ByVal Hex As String) As Long Dim i As Long Dim B As Long Hex = UCase(Hex) For i = 1 To Len(Hex) Select Case Mid(Hex,Len(Hex) - i + 1,1) Case "0": B = B + 16 ^ (i - 1) * 0 Case "1": B = B + 16 ^ (i - 1) * 1 Case "2": B = B + 16 ^ (i - 1) * 2 Case "3": B = B + 16 ^ (i - 1) * 3 Case "4": B = B + 16 ^ (i - 1) * 4 Case "5": B = B + 16 ^ (i - 1) * 5 Case "6": B = B + 16 ^ (i - 1) * 6 Case "7": B = B + 16 ^ (i - 1) * 7 Case "8": B = B + 16 ^ (i - 1) * 8 Case "9": B = B + 16 ^ (i - 1) * 9 Case "A": B = B + 16 ^ (i - 1) * 10 Case "B": B = B + 16 ^ (i - 1) * 11 Case "C": B = B + 16 ^ (i - 1) * 12 Case "D": B = B + 16 ^ (i - 1) * 13 Case "E": B = B + 16 ^ (i - 1) * 14 Case "F": B = B + 16 ^ (i - 1) * 15 End Select Next i HEX_to_DEC = B End Function '将Long整型数据转换为16进制字符串 Public Function DEC_to_HEX(Dec As Long) As String Dim a As String DEC_to_HEX = "" If Dec = 0 Then '为零时处理 DEC_to_HEX = "00" Exit Function End If Do While Dec > 0 a = CStr(Dec Mod 16) Select Case a Case "10": a = "A" Case "11": a = "B" Case "12": a = "C" Case "13": a = "D" Case "14": a = "E" Case "15": a = "F" End Select DEC_to_HEX = a & DEC_to_HEX Dec = Dec \ 16 Loop If Len(DEC_to_HEX) Mod 2 <> 0 Then '补零操作 DEC_to_HEX = "0" & DEC_to_HEX End If End Function
2.求整型数据的高位值与低位值,因vb中未找到无符号整型的数据类型,下面的例子用Long数据类型来进行替代。数据范围在(0-65535)之间。
Private Sub btnTest_Click() Dim iValue As Long Dim iHighValue As Byte Dim iLowValue As Byte iValue = 65000 iHighValue = ((iValue And &HFF00) \ &H100) And &HFF iLowValue = iValue And &HFF End Sub上面相关的方法仅作为记录,便于以后查找。 原文链接:https://www.f2er.com/vb/258754.html