vb打开外部文件以二进制(0和1)显示到richtextbox1中
PrivateSubCommand1_Click()RichTextBox1.Text=""OpenApp.Path&"\1.exe"ForBinaryAs#1?????...
Private Sub Command1_Click()
RichTextBox1.Text = ""
Open App.Path & "\1.exe" For Binary As #1
??????
a=?????
RichTextBox1.Text = a
Close #1
End Sub 展开
RichTextBox1.Text = ""
Open App.Path & "\1.exe" For Binary As #1
??????
a=?????
RichTextBox1.Text = a
Close #1
End Sub 展开
2个回答
展开全部
'文件不能太大啊! 否则会愈大愈慢,没分我就懒得做分段处理的代码了
Private Sub Command1_Click()
Dim a As String
Dim tmpStr As String
Dim Buffer() As Byte
Dim ABit As Long
RichTextBox1.Text = ""
Open "E:\1.txt" For Binary As #1
ReDim Buffer(LOF(1) - 1)
Get #1, , Buffer
For i = 0 To UBound(Buffer)
For j = 0 To 7
ABit = Buffer(i) And (2 ^ (7 - j))
If ABit > 0 Then
ABit = 1
Else
ABit = 0
End If
a = a & ABit
Next
'a = a & ","'用逗号隔开每一个字节
Next
RichTextBox1.Text = a
Close #1
End Sub
Private Sub Command1_Click()
Dim a As String
Dim tmpStr As String
Dim Buffer() As Byte
Dim ABit As Long
RichTextBox1.Text = ""
Open "E:\1.txt" For Binary As #1
ReDim Buffer(LOF(1) - 1)
Get #1, , Buffer
For i = 0 To UBound(Buffer)
For j = 0 To 7
ABit = Buffer(i) And (2 ^ (7 - j))
If ABit > 0 Then
ABit = 1
Else
ABit = 0
End If
a = a & ABit
Next
'a = a & ","'用逗号隔开每一个字节
Next
RichTextBox1.Text = a
Close #1
End Sub
2011-09-19
展开全部
读取文件,转换成ASC码,再在RichTextBox中显示。
追问
有具体的吗?
我看不懂
追答
看个例子:
'读取文件到数组中
Dim bytes() As Byte
dim lLength as Long
Open "c:\main.exe" For Binary As #1 '读取字节
lLength=LOF(1)
ReDim bytes(1 To lLength) As Byte
Get 1, , bytes
Close #1
'将文件以十六进制方式输出到Text1中,这个过程很耗时,文件越大,速度越慢
Dim strTmp As String
For i = 1 To lLength
strTmp = strTmp & " " & Hex(bytes(i))
DoEvents
Next
Text1.Text = strTmp '这里把Text1改为richtextbox1
'存储文件
Open "c:\Bin4Save.Bin" For Binary As #1
Put 1, , bytes
Close #1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询