vb编程基础问题,送分啦

2024-12-02 20:38:04
推荐回答(2个)
回答1:

先弹出对话框,然后在用FileName 获得文件名

CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
Text1.Text = CommonDialog1.FileName
End If

当然这个只是演示要想保存最简单的方法是用 RichTextbox 控件他带有 SaveFile 属性可以实现保存文件方法是:

RichTextBox1.SaveFile CommonDialog1.FileName, 1

参数最后一个如果是0则保存为RTF格式是1保存为TXT文本格式!

回答2:

Public Sub savepro()
On Error GoTo errtrap
CommonDialog1.CancelError = True
CommonDialog1.Filter = \"文本文件(*.txt)|*.txt\"
CommonDialog1.Flags = &H2
CommonDialog1.ShowSave
If CommonDialog1.FileName <> \"\" Then
fn = FreeFile
Open CommonDialog1.FileName For Output As fn
Print #fn, text1.Text
Close fn
end if
Exit Sub
errtrap:
end sub