Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving files in different format depending on filter chosen 1

Status
Not open for further replies.

michelleDub

Technical User
Jun 3, 2003
16
IE
hi,
I'm trying to save details from a VB application in two ways. Firstly as a .txt file which stores variable valuse which can be reloaded to the application from the text file.
however I would alos like the user to be able to choose to save the file as a html file which will save a table of the variables and their values.
I'm using the Common Dialog and I have a .txt and .html filters. I want the outputs for the save to be different depending on the filter type chosen. I know I could do this with an if statement with something like
'If (file type = html file) then
'Write ...............
'Else
'Write .............
'End If

If anyone knows how I can check the chosen filter for the if statement it would be great.
thanks
Michelle
 
You can determine the filter selected with the CommonDialog's FilterIndex property. If you set up the filter like this:

CommonDialog1.Filter = "Text (*.txt)|*.txt|HTML (*.html)|*.html"

In this filter, text files (*.txt) have a FilterIndex of 1, and HTML files (*.html) have a FilterIndex of 2. The FilterIndex always starts at 1 and increments by 1 for each filter in the filter list. So, you could check like this:

If CommonDialog1.FilterIndex = 1 Then 'Text files
'save text file
ElseIf CommonDialog1.FilterIndex = 2 Then 'HTML files
'save HTML file
EndIf

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top