Results 1 to 6 of 6

Thread: File Types And Extensions?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Question File Types And Extensions?

    Hi,

    a = "abcd.htm" or "abgh.html" or "ahfgffg.aspx" or "tytyty.asp"

    How to find the last 4 or 3 characters(file extensions eg: *.doc) from the above filenames using VB?

    Thanks,
    Murtaza

  2. #2
    Hyperactive Member binilmb's Avatar
    Join Date
    Nov 2005
    Location
    Kochi
    Posts
    472

    Re: File Types And Extensions?

    This will work for u

    VB Code:
    1. Dim St
    2. St = Right(Text1.Text, Len(Text1.Text) - InStrRev(Text1.Text, "."))
    3. MsgBox St
    įňįl

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Question Re: File Types And Extensions?

    Hi,

    I don't have Text1 and Text...I have a single variable which may store files with extensions such as *.html or *.htm or *.doc etc.

  4. #4

    Re: File Types And Extensions?

    so replace text1.text with "a" for example if thats the variable your holding the file name in.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    58

    Question Re: File Types And Extensions?

    Can we do it using split or array functions?

  6. #6
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: File Types And Extensions?

    Quote Originally Posted by smurtaza
    Can we do it using split or array functions?
    yes...

    VB Code:
    1. Dim test As String 'original variable data
    2. Dim temp() As String 'array
    3. Dim Extension As String 'final extension
    4.  
    5. test = "abcd.doc" 'define test data
    6.  
    7. temp = Split(test, ".") 'split it to array
    8. Extension = "." & temp(UBound(temp)) 'grab the extension
    9.  
    10. MsgBox Extension
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width