www.pudn.com > kelon.rar > mod03.bas
Attribute VB_Name = "mod03"
Option Explicit
Public Function MM2Text(ByVal vMM As String) As String
Dim s1 As String
s1 = vMM
Dim s10(16) As String
Dim s11(16) As Long
Dim I As Long
For I = 0 To 16
s10(I) = Mid(s1, (I * 2) + 1, 2) '取17个数
s11(I) = hex2num(s10(I)) '转换为十进制
Next
Dim s12(8) As Long
Dim s13(7) As String
For I = 0 To 16
If I > 7 Then '取0,2,4,6,8----16
s12(I - 8) = s11(I)
s12(I - 8) = 256 - s12(I - 8)
Else
s13(I) = s11(I) '取 1,3,5,7,----15
s13(I) = 256 - s13(I)
End If
Next
Dim s14(16) As Long
Dim s15(16) As String
For I = 0 To 16 '
Select Case I
Case 1, 3, 5, 7, 9, 11, 13, 15, 17
s14(I) = s13(I \ 2)
Case 0, 2, 4, 6, 8, 10, 12, 14, 16
s14(I) = s12(I \ 2)
End Select
s15(I) = Chr(s14(I))
Next
Dim s2 As String
For I = 0 To 16
s2 = s2 + s15(I)
Next
Dim s4 As Long
s4 = hex2num(Left(s2, 1))
Dim s5 As String
s5 = Right(s2, 17 - s4 - 1)
MM2Text = s5
End Function
Public Function Text2MM(ByVal vStr As String) As String
Dim s1 As String
Dim l1 As Long
s1 = vStr
l1 = Len(s1)
'define 16 bit
Dim l2 As Long
l2 = 16 - l1
Dim s2 As String
s2 = Left("1234567890abcdef", l2)
Dim s3 As String, s4 As String
s3 = Hex(l2)
s2 = s3 + s2 + s1
Dim I As Long
Dim s10(16) As Long, s11(16) As Long
For I = 0 To 16
s10(I) = Asc(Mid(s2, I + 1, 1))
s11(I) = 256 - s10(I)
Next
Dim s5 As String
Dim s6 As String
For I = 0 To 16 Step 2 '取0,2,4,6,8----16
s5 = Hex(s11(I))
s5 = IIf(Len(s5) = 1, "0" + s5, s5) '两位16进制数
s6 = s6 + s5
Next
Dim s7 As String
For I = 1 To 16 Step 2 '取 1,3,5,7,----15
s5 = Hex(s11(I))
s5 = IIf(Len(s5) = 1, "0" + s5, s5) '两位16进制数
s7 = s7 + s5
Next
s7 = s7 + s6 '1,3,5,7,----15 0,2,4,6,8----16
Text2MM = s7
End Function
Private Function hex2num(ByVal sHex As String) As Long
Dim s1 As String, s2 As String
Dim l1 As Long, l2 As Long
l1 = -1
l2 = -1
If Len(sHex) = 1 Then
s1 = "0"
Else
s1 = Left(sHex, 1)
End If
s2 = Right(sHex, 1)
If s1 = "a" Or s1 = "A" Then l1 = 10
If s1 = "b" Or s1 = "B" Then l1 = 11
If s1 = "c" Or s1 = "C" Then l1 = 12
If s1 = "d" Or s1 = "D" Then l1 = 13
If s1 = "e" Or s1 = "E" Then l1 = 14
If s1 = "f" Or s1 = "F" Then l1 = 15
If l1 = -1 Then l1 = Val(s1)
If s2 = "a" Or s2 = "A" Then l2 = 10
If s2 = "b" Or s2 = "B" Then l2 = 11
If s2 = "c" Or s2 = "C" Then l2 = 12
If s2 = "d" Or s2 = "D" Then l2 = 13
If s2 = "e" Or s2 = "E" Then l2 = 14
If s2 = "f" Or s2 = "F" Then l2 = 15
If l2 = -1 Then l2 = Val(s2)
hex2num = l1 * 16 + l2
End Function