为何保存为空文件?

ywdevil 2000-11-01 09:37:00
为何保存时为空文件?

'1 假如保存为txt文件
Private Sub mnuFileSaveAs_Click()
common1.CancelError = True
common1.Filter = "TxT (*.txt)|*.txt|"
common1.FileName = "Untitled.txt"
common1.FilterIndex = 1
common1.ShowSave
FileName = common1.FileName
If common1.FileName = "" Then Exit Sub
Open common1.FileName For Output As 1
Close
Caption = "Files M3u - " + common1.FileName
End Sub
'2 假如保存为txt文件
Private Sub mnuFileSaveAs_Click()
On Error GoTo errStop
common1.CancelError = True
common1.Filter = "TxT (*.为何txt)|*.txt|"
common1.FileName = "untitled.txt"
common1.ShowSave
Open common1.FileName For Output As #1
For i = 0 To List1.ListCount - 1
a$ = List1.List(i)
Print #1, a$
Next
Close #1

errStop:
Exit Sub


End Sub
...全文
155 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Edward 2000-11-02
  • 打赏
  • 举报
回复
呵呵,虽然我不明白你的问题,但是有一点注意的地方:
大多数情况下你的程序是对的,但是如果文件号 #1 因为某种原因已经被使用,那么你的程序就会出错,建议先用 FreeFile 得到空闲的文件号。

你最好用单步跟踪的方法调试一边你的程序,而且暂时把 On Error Gotp errStop 注释掉或在 errStop 后面用 Debug.Print Err.Description 看一下有什么错误发生。
gameboy999 2000-11-02
  • 打赏
  • 举报
回复
不知道你的'1是干什么的,那必然存为一个空文件(而且有可能出错)
但'2应该是可以存的,可是你用了出错控制,有可能#1被占用而导致失败你却得不到提示,最好是获得一个空闲的文件名或是探测commondialog.showsave的返回值,看是否出错。

wjhtz 2000-11-02
  • 打赏
  • 举报
回复
Open common1.FileName For Output As #1

你这里得到的common1.FileName可能不是真正的文件名.[记得不太清楚]
单步执行看看,或者#1被占用.再有问题请写信给我,互相探讨,OK? wjh26tz@sina.com

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧