新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim strFN As String
Dim fileSize As Long
Dim byteArray() As Byte
Dim i As Integer
' 设置要读取的文件路径
strFN = "a.exe"
' 以二进制模式打开文件
Open strFN For Binary As #1
' 获取文件大小
fileSize = LOF(1)
' 调整数组大小以容纳整个文件
ReDim byteArray(fileSize - 1)
' 从文件中读取内容到字节数组
Get #1, , byteArray
' 关闭文件
Close #1
' 这里可以对读取到的 byteArray 进行进一步处理
' 例如,你可以遍历数组查看每个字节的值
For i = LBound(byteArray) To UBound(byteArray)
Debug.Print byteArray(i)
Next i
MsgBox "文件读取完成,已存储到字节数组中。"
End Sub