您的位置: 网站首页 > 编程乐园 > 阅读文章

伟伟VB编程系列┊VB之打开与保存文件

VB打开保存文件

  从部件里添加一个CommonDialog控件,写入代码:

CommonDialog1.Filter = "文本文档(*.txt)|*.txt|ASP文件(*.asp)|*.asp|VBS脚本(*.vbs)|*.vbs|所有文件(*.*)|*.*" '显示要保存的所有类型
CommonDialog1.filterindex = 1 '默认保存文件的类型
CommonDialog1.Action = 2 '1为打开,2为保存
Dim str As String
str = CommonDialog1.FileName 'str等于输入保存的文件名
If (Trim(str) <> "") Then
   Set fso = CreateObject("scripting.filesystemobject")
   Set txt = fso.createtextfile(str)
   txt.write (Text1.Text)
   MsgBox "文件保存成功!", vbOKOnly + vbInformation, "操作提示"
End If
  • 属于分类: 编程乐园
  • 本文标签:
  • 人气指数: 3,631
  • 文章作者: 野球小子
  • 生产日期: 2007年8月22日 - 9时07分34秒
看看还有没有您感兴趣的:

  • 您的大名(必填)
  • E-Mail (必填)
  • 您的网站(有的话就写一下吧~)
  • 评论内容:(必填)