【VBA】2進数を文字列に変換する(前回の続き)
Option Explicit Public Sub 読み込んだ2進数を文字列に変換() Dim filePath As String Dim fileNo As Long Dim txt As String Dim txts() As String Dim i As Long filePath = ThisWorkbook.Path & "\binary.dat" fileNo = FreeFile Open filePath For Input As #fileNo Line Input #fileNo, txt Close #fileNo txt = decode(txt) txts = Split(txt, vbCrLf) For i = 0 To UBound(txts) Debug.Print txts(i) Next End Sub '2進数から文字列に変換 Private Function decode(ByVal txt As String) As String Dim i As Long Dim bin As String Dim res As String For i = 1 To Len(txt) Step 8 bin = Mid(txt, i, 8) res = res & Chr(WorksheetFunction.Bin2Dec(bin)) Next decode = res End Function