
关于vb对二进制的一些问题
例如:要把字符串str="Hello World"转换成二进制要怎么搞?
再把转换后的写入文件"1.dat"要怎么做
请大佬们通俗but详细地介绍一下 展开
Dim t As String, f As String
Private Sub Command1_Click()
On Error GoTo myerr
Dim hFile As Long, bb() As Byte
bb = t
hFile = FreeFile
Open f For Binary As #hFile
Put #hFile, , bb
Close #hFile
Exit Sub
myerr:
MsgBox Err.Description
End Sub
Private Sub Command2_Click()
On Error GoTo myerr
Dim hFile As Long, bb() As Byte, s As String
hFile = FreeFile
Open f For Binary As #hFile
ReDim bb(LOF(hFile) - 1)
Get #hFile, , bb
Close #hFile
s = StrConv(bb, vbNarrow)
MsgBox s
Exit Sub
myerr:
WriteAndReadByteFile = Err.Description
End Sub
Private Sub Form_Load()
t = "中国,hello word,中国"
f = App.Path & "\1.dat"
Command1.Caption = "写入"
Command2.Caption = "读取"
End Sub