求教如何打开和保存文件
我想保存个数组文件,想使用通用对话框来做打开和保存,请问要想保存这个数组该怎么做?看VB的书对文件的操作很麻烦还没学会,请问结合书本上的实现方法.谢谢. …
提供个Binary模式存取档案的参考:
Sub saveBinary() 'Binary模式写入档案
Dim iArr() As Byte, i As Long, F As Integer, fPath As String
fPath = "c:\AA.bin" '写入路径
'不明白你的资料来源是什麽,所以做个Array来模拟存档
ReDim iArr(255)
For i = 0 To UBound(iArr)
iArr(i) = i
Next 'i
If Dir(fPath) <> "" Then Kill fPath '原档存在则删除原档
F = FreeFile '取得可用档案
Open fPath For Binary As #F '开档
Put #F, , iArr '一次存入Array
Close #F '关档
End Sub
Sub readBinary() 'Binary模式读取档案
Dim iArr() As Byte, i As Long, F As Integer, fPath As String
fPath = "c:\AA.bin" '档案读取路径
i = FileLen(fPath) '取得档案大小
ReDim iArr(i - 1) '制作Array以读入
F = FreeFile '取得可用档案
Open fPath For Binary As #F '开档
Get #F, 1, iArr '以Binary模式一次读入整个档案
Close #F '关档
End Sub