vb打开外部文件以二进制(0和1)显示到richtextbox1中

2024-11-25 18:20:09
推荐回答(2个)
回答1:

'文件不能太大啊! 否则会愈大愈慢,没分我就懒得做分段处理的代码了
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

回答2:

读取文件,转换成ASC码,再在RichTextBox中显示。