文本保存时,1.如何提示是否覆盖同名文件?

hoo 2001-11-27 06:25:42
2.遇到要用默认文件名时(可省去添加文件名这一步骤),但因为不知是否有你预备认定的目录时,你们如何处理?
例如:我编了一个程序(.exe文件),它要求存一个数据文件,假如‘另存为’中为空,即会出错,这时我只好另认定一个文件名,规定它在C:\windows\temp下,可好象太麻烦了,此时,你们如何解决的?
...全文
233 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
enmity 2001-11-27
  • 打赏
  • 举报
回复
判断文件是否存在,可以使用下面的函数:

Public Function FileExists%(FileName$)

Dim f%

' Trap any errors that may occur
On Error Resume Next

' Get a free file handle to avoid using a file handle already in use
f% = FreeFile
' Open the file for reading
Open FileName$ For Input As #f%
' Close it
Close #f%
' If there was an error, Err will be <> 0. In that case, we return False
FileExists% = Not (Err <> 0)

End Function

使用:
if Function FileExists("c:\abc.txt")<>0 then
msgbox "文件存在"
endif
fishzone 2001-11-27
  • 打赏
  • 举报
回复
写错了,是commondialog
fishzone 2001-11-27
  • 打赏
  • 举报
回复
1 先用dir查找此文件,如果存在,则提示覆盖。
2 用commanddialog的showsave调出通用对话框。给它赋却省的文件名

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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