怎样用VB打开二进制文件,并用文本框显示出来
例如:打开C盘之下的1.TXT文件,文件里面是一篇文章,怎样用Binary打开读出,并把文件内容在文本框显示注:别用INPUT打开,因为我要求是用二进制方式打开....
例如:打开C盘之下的 1.TXT文件,文件里面是一篇文章,怎样用Binary打开读出,并把文件内容在文本框显示
注:别用INPUT打开,因为我要求是用二进制方式打开. 展开
注:别用INPUT打开,因为我要求是用二进制方式打开. 展开
展开全部
Private Sub Form_Load()
Dim Temp() As Byte
Dim Templen As Long
Templen = FileLen("c:\1.txt")
ReDim Temp(1 To Templen) As Byte
Open "c:\1.txt" For Binary As #1
Get #1, , Temp
Close #NUM
'''''''放到text中,不支持汉字不知道怎么样可以支持汉字''''''''''
For i = 1 To Templen
Text1.Text = Text1.Text & Chr(Temp(i))
Next i
''''''输出到文件,这个支持汉字和所有字符'''''''''''''''''''''''''''''''''''''''
Open "c:\2.txt" For Binary As #2
Put #2, , Temp
Close #2
End Sub
Dim Temp() As Byte
Dim Templen As Long
Templen = FileLen("c:\1.txt")
ReDim Temp(1 To Templen) As Byte
Open "c:\1.txt" For Binary As #1
Get #1, , Temp
Close #NUM
'''''''放到text中,不支持汉字不知道怎么样可以支持汉字''''''''''
For i = 1 To Templen
Text1.Text = Text1.Text & Chr(Temp(i))
Next i
''''''输出到文件,这个支持汉字和所有字符'''''''''''''''''''''''''''''''''''''''
Open "c:\2.txt" For Binary As #2
Put #2, , Temp
Close #2
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是不是这个意思?
Private Sub Form_Load()
Dim a As Byte, i As Integer, b As String
Open "c:\1.txt" For Binary As #1
Get #1, , a
Do Until EOF(1)
Get #1, , a
b = Hex(a)
If Len(b) = 1 Then b = "0" & b
Text1 = Text1 & " " & b
i = i + 1
If i = 8 Then Text1 = Text1 & vbCrLf: i = 0
Loop
Close #1
End Sub
Private Sub Form_Load()
Dim a As Byte, i As Integer, b As String
Open "c:\1.txt" For Binary As #1
Get #1, , a
Do Until EOF(1)
Get #1, , a
b = Hex(a)
If Len(b) = 1 Then b = "0" & b
Text1 = Text1 & " " & b
i = i + 1
If i = 8 Then Text1 = Text1 & vbCrLf: i = 0
Loop
Close #1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1楼lairice正解,这个方式无关汉字或半角问题,直接读即可,简单实用,实在是好东西
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Open "C:\1.TXT" For Binary As #1
Text1.Text = StrConv(InputB$(LOF(1), 1), 64)
Close #1
Text1.Text = StrConv(InputB$(LOF(1), 1), 64)
Close #1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim dd as Double
Open "c:\1.txt" For Binary As #1
dd = LOF(1)
Text1.Text = Input(dd, #1)
Close #1
Open "c:\1.txt" For Binary As #1
dd = LOF(1)
Text1.Text = Input(dd, #1)
Close #1
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询