?
Solved

Find File Format from VB6?

Posted on 2003-03-28
10
Medium Priority
?
310 Views
Last Modified: 2010-05-01
While user opening a file from the Commondialog Box,
How can differentiate the File name and the File Type (as .PDF or .DOC or .TXT etc)
0
Comment
Question by:u2kim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8223776
Try:

Extension = Right$(CommonDialog1.FileName,4)

cheers
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 100 total points
ID: 8223785
To get file Name and file type:

Dim tmpArr() as string

tmpArr = split(CommonDialog1.FileName,".",,vbtextcompare)

if ubound(tmpArr) =1 then
   filename = tmparr(0)
   filetype = tmparr(1)
end if
0
 

Expert Comment

by:itzme
ID: 8223826
This will put the value of the filetype into extension(1):

     Dim extension() As String

     extension = "." & Split(.FileTitle, ".", -1, vbTextCompare)

Hope thats what you want, to differentiate between all of them store this in an array of all the extensions.

The other thing you could be looking for could be filters, before the ".showOpen" (close,etc) in your code put in:

.Filter = "PostScript|*.pdf"&"|Word Document|*.doc"

and so on then put in the ".showOpen" bit. Hope one of these is what you want.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:itzme
ID: 8223828
This will put the value of the filetype into extension(1):

     Dim extension() As String

     extension = "." & Split(.FileTitle, ".", -1, vbTextCompare)

Hope thats what you want, to differentiate between all of them store this in an array of all the extensions.

The other thing you could be looking for could be filters, before the ".showOpen" (close,etc) in your code put in:

.Filter = "PostScript|*.pdf"&"|Word Document|*.doc"

and so on then put in the ".showOpen" bit. Hope one of these is what you want.
0
 
LVL 3

Expert Comment

by:VBtom
ID: 8224165
What exactly do you want?
If you want to get the extension of the chosen file, look at ryancys' solution (or better itzme's: some extensions can have 4 characters and then ryancys' method fails).

But, as I understood, if you want to give the user the opportuntity to choose a file type, use (before the showopen or showsave):
CommonDialog1.Filter = "PDF-documents|*.pdf|Word-documents|*.doc|Text files|*.txt"
0
 

Author Comment

by:u2kim
ID: 8224171
I wont get the file name like Report1.DOC or Report1.PDF.
I will get the file name  as "Report1"  without any extension.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8224214
>>I will get the file name  as "Report1"  without any extension.
Tried the method i have posted and it should return the answer.
0
 

Expert Comment

by:itzme
ID: 8224592
Are you talking about the filename displayed in the common dialog box or the filename returned from the "commondialog1.Filename" paramater, if its the one in the filelist displayed by the common dialog box its because you've turned of the "show all file types" in "folder options" in windows.
0
 

Expert Comment

by:CleanupPing
ID: 8531427
Hi u2kim,
This old question (QID 20566211) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9440837
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept ryancys's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question