|
善くTest指定無いので上手く動くのか?
以下を標準モジュールに記述して下さい
Option Explicit
Public Function Decode(ByVal strValue As String) As String
Dim i As Long
Dim strBuff As String
Dim strResult As String
If strValue = "" Then
Exit Function
End If
For i = 1 To Len(strValue) Step 8
strBuff = Mid(strValue, i, 8)
strResult = strResult & Chr(ToDecimal(strBuff, 2))
Next i
Decode = strResult
End Function
Public Function ToDecimal(ByVal strValue As String, _
ByVal lngSystem As Long) As Long
Dim i As Long
Dim lngWeight As Long
Dim lngLeng As Long
Dim lngResult As Long
Dim lngBase As Long
Dim strBase As String
If strValue = "" Then
Exit Function
End If
strValue = StrConv(strValue, vbNarrow + vbUpperCase)
lngLeng = Len(strValue)
lngWeight = lngSystem ^ (lngLeng - 1)
For i = 1 To lngLeng
strBase = Mid(strValue, i, 1)
Select Case Asc(strBase)
Case 48 To 57
lngBase = CLng(strBase)
Case 65 To 90
lngBase = 10 + Asc(strBase) - 65
Case Else
Exit Function
End Select
lngResult = lngResult + lngBase * lngWeight
lngWeight = lngWeight \ lngSystem
Next i
ToDecimal = lngResult
End Function
UserFormのTextBox2に有る値をCommandButton1を押すと
TextBox3に結果を表示します
Private Sub CommandButton1_Click()
TextBox3.Text = Decode(TextBox2.Text)
End Sub
|
|