1

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.

0

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

2 Comments

Is there a way to define a default extension when using this method? Like if Text is selected to auto append .txt to the end of it.
@PaulWilliams It's automatic. To see that, you can (temporarily) set the Text property of your form to the file's name. In C# it would be done like this: Text = saveFileDialog1.FileName; . What I get if I type "abc" is: C:\Users\...\abc.txt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.