vb如保存二进制文件
如何保存这样内容的文件(下面是二进制内容)0001101000111001010011100100000011010001101000111001010011100100...
如何保存这样内容的文件(下面是二进制内容)000110100011100101001110010000001101000110100011100101001110010000001101000110100011100101001110010000001101000110100011100101001110010000001101
保存为文件名为123.abc的文件
最好有代码
谢谢
解决后还会加分
能具体点吗?最好有代码,谢谢! 展开
保存为文件名为123.abc的文件
最好有代码
谢谢
解决后还会加分
能具体点吗?最好有代码,谢谢! 展开
2个回答
展开全部
Private Sub Command1_Click()
Dim fs
Dim a, i, j, k As Integer
Dim numStr, temp, hexStr As String
Dim TwoByte() As Byte
Set fs = CreateObject("Scripting.FileSystemObject")
Open App.Path & "\123.abc" For Binary Access Write As #1
numStr = "000110100011100101001110010000001101000110100011100101001110010000001101000110100011100101001110010000001101000110100011100101001110010000001101"
ReDim TwoByte(Len(numStr) / 8-1)
k = 0
While Len(numStr) > 0
temp = Left(numStr, 4)
numStr = Right(numStr, Len(numStr) - 4)
For i = 0 To 3
a = a + CInt(Right(temp, 1)) * 2 ^ i
'Debug.Print a
temp = Left(temp, 3 - i)
Next i
j = j + 1
hexStr = hexStr & CStr(Hex(a))
If j = 2 Then
TwoByte(k) = Val("&H" & hexStr)
j = 0
hexStr = ""
k = k + 1
End If
a = 0
Wend
Put #1, , TwoByte
Close #1
Unload Me
End Sub
'已经调试完成的。
Dim fs
Dim a, i, j, k As Integer
Dim numStr, temp, hexStr As String
Dim TwoByte() As Byte
Set fs = CreateObject("Scripting.FileSystemObject")
Open App.Path & "\123.abc" For Binary Access Write As #1
numStr = "000110100011100101001110010000001101000110100011100101001110010000001101000110100011100101001110010000001101000110100011100101001110010000001101"
ReDim TwoByte(Len(numStr) / 8-1)
k = 0
While Len(numStr) > 0
temp = Left(numStr, 4)
numStr = Right(numStr, Len(numStr) - 4)
For i = 0 To 3
a = a + CInt(Right(temp, 1)) * 2 ^ i
'Debug.Print a
temp = Left(temp, 3 - i)
Next i
j = j + 1
hexStr = hexStr & CStr(Hex(a))
If j = 2 Then
TwoByte(k) = Val("&H" & hexStr)
j = 0
hexStr = ""
k = k + 1
End If
a = 0
Wend
Put #1, , TwoByte
Close #1
Unload Me
End Sub
'已经调试完成的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询