Function GetLengthSMSC(pdu As String) As Variant
Dim inicio As Integer
inicio = 1
pdu_temp = Val("&H" & (Mid(pdu, inicio, 2)))
GetLengthSMSC = pdu_temp
End Function
Function GetLengthAddress(pdu As String) As Variant
Dim posicion As Integer
posicion = (GetLengthSMSC(pdu)) * 2 + 5
pdu_temp = Val("&H" & (Mid(pdu, posicion, 2)))
GetLengthAddress = pdu_temp
End Function
Function GetUserDataLength(pdu As String) As Variant
Dim posicion As Integer
If GetLengthAddress(pdu) / 2 = Int(GetLengthAddress(pdu) / 2) Then
posicion = (GetLengthSMSC(pdu)) * 2 + 27 + GetLengthAddress(pdu)
Else
posicion = (GetLengthSMSC(pdu)) * 2 + 28 + GetLengthAddress(pdu)
End If
pdu_temp = Val("&H" & (Mid(pdu, posicion, 2)))
GetUserDataLength = pdu_temp
End Function
Function GetUserMessageDecoded(pdu As String) As String
Dim temp As Double
Dim temp_left As Double
Dim mensaje_temp As String
Dim posicion As Integer
If GetLengthAddress(pdu) / 2 = Int(GetLengthAddress(pdu) / 2) Then
posicion = (GetLengthSMSC(pdu)) * 2 + 29 + GetLengthAddress(pdu)
Else
posicion = (GetLengthSMSC(pdu)) * 2 + 30 + GetLengthAddress(pdu)
End If
For i = 0 To (Len(pdu) - posicion) / 2
If ((i Mod 7) = 0) And i <> 0 Then
mensaje_temp = mensaje_temp & Chr$(temp_left)
temp_left = 0
End If
temp = 2 ^ (i Mod 7) * (Val("&H" & (Mid(pdu, posicion + (2 * i), 2))) Mod 2 ^ (7 - (i Mod 7))) + temp_left
temp_left = Val("&H" & (Mid(pdu, posicion + (2 * i), 2))) \ 2 ^ (7 - (i Mod 7))
mensaje_temp = mensaje_temp & Chr$(temp)
Next i
GetUserMessageDecoded = Mid$(mensaje_temp, 1, GetUserDataLength(pdu))
End Function