当前位置:编程学习 > VB >>

请教VB做的文件另存功能!!

请教VB做的文件另存功能!!
功能 :浏览任意一个文件,另存到用户指定地方,如果这地方已有这个文件,提示是否替换掉。
界面:CommonDialog1  text1【浏览文件路径(含文件名)】  command1【浏览按钮】 command2【另存按键】
我的代码:
Private Sub Command1_Click()
    Text1.Text = ""
    CommonDialog1.Filter = "All File"
    CommonDialog1.FileName = ""
    CommonDialog1.ShowOpen
    Text1.Text = CommonDialog1.FileName
End Sub

Private Sub Command2_Click()
If Text1.Text = "" Then Exit Sub '没有资源,不复制
    oldfilename = Mid(Text1.Text, InStrRev(Text1.Text, "\") + 1)   '取得原文件名,用于保存时提示文件名
    CommonDialog1.DialogTitle = "@另存为:"
    CommonDialog1.Filter = "ALL File"
    CommonDialog1.ShowSave
    If Dir(CommonDialog1.FileName) <> vbNullString Then   '同文件夹有同名文件
               If MsgBox("" & CommonDialog1.FileName & "已存在," & Chr(13) & "要替换它吗?", vbYesNo + 48, "另存为") = vbYes Then '提示是否替换
                  Kill CommonDialog1.FileName '替换:先kill
                  FileCopy "" & Text1.Text & "", CommonDialog1.FileName  '替换:后保存
                  MsgBox "替换保存OK"
               End If
     Else  '没有同文件名,直接保存
                  FileCopy "" & Text1.Text & "", CommonDialog1.FileName
                  MsgBox "直接保存OK"
    End If
End Sub


问题出现了:
1.保存时,我换名保存的文件,没有了后缀名。
2.如果保存一次,再次保存,发现已有这个文件,按“取消”,结果程序还是给保存了。
3.因为是可复制任意类型文件,在CommonDialog1的CommonDialog1.Filter指定文件的类型?

成功的例子:如用ie下载(非快车,非迅雷) 另保存  这一系列动作.
这个问题不难吧,仔细点就是了
补充:VB ,  非技术类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,