简体   繁体   中英

Using one Save File Dialog Box in Visual Basic

Currently I have three separate save commands in my program: Write to Plain Text, Write to HTML, and Write to Excel File.

Each one is invoked by a different command on a menu. I would like to combine these three into one Save File Dialog on the program. I know that I would have to edit the "Filter" property of the dialog box to add in the other two types.

My questions, how do I code the program to save the file based off what is chosen from the filter. That's to say :

If "Selected = Microsoft Excel" Then
    * Save As Excel File
ElseIf "Selected = HTML Then
    * Save As HTML File
Else 
    * Save As Plain Text File
End If

Thanks for any response.

Here's a snippet to give you an idea. Sorry it's in C#, but it should be easy to convert to VB.

EDIT: here's the new code:

saveFileDialog1.Filter = "Text|*.txt|Word|*.docx";
saveFileDialog1.ShowDialog();            
if (saveFileDialog1.FilterIndex == 2) MessageBox.Show("It's a Word doc.");
saveFileDialog1.Dispose();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM