Private Sub Command1_Click() CommonDialog1.ShowOpen If CommonDialog1.filename <> "" Then
Dim TempFile As Long Dim LoadBytes() As Byte
TempFile = FreeFile Open CommonDialog1.filename For Binary As #TempFile ReDim LoadBytes(1 To LOF(TempFile)) As Byte Get #TempFile, , LoadBytes Close TempFile
Text1.Text = StrConv(LoadBytes, vbUnicode) End If End Sub
公用对话框提供给你的只是一个界面以及文件的全路径而已,并不能让你打开什么文件,你只能通过代码来打开你在这个对话框中所获得的文件,就如楼上的代码所示,不过楼上的代码当中还应当加上:commondialog1.cancelerror=true on error resume next 这样才不至于在你单击对话框的取消按钮时出错,同时,当你显示的是字体或打印对话框时还要注意设置flags的值,设置不对就会出错
CommoDialog1.ShowSave '保存
If CommonDialog1.filename <> "" Then
Dim TempFile As Long
Dim LoadBytes() As Byte
TempFile = FreeFile
Open CommonDialog1.filename For Binary As #TempFile
ReDim LoadBytes(1 To LOF(TempFile)) As Byte
Get #TempFile, , LoadBytes
Close TempFile
Text1.Text = StrConv(LoadBytes, vbUnicode) End If
End Sub
on error resume next
这样才不至于在你单击对话框的取消按钮时出错,同时,当你显示的是字体或打印对话框时还要注意设置flags的值,设置不对就会出错
读写,好象更方便些