|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Determine if: > .dat < is in a stringI need to determine file type from the file path and name which I get from
the CommonDialog control. What is the best way? -- Thank you, Randy > I need to determine file type from the file path and name As long as the cdlOFNNoValidate flag is NOT set (I can't think of any reason > which I get from the CommonDialog control. it should be), you can use this code to get the file's name and extension... Dim FilesName As String Dim FilesExtension As String Dim NameParts() As String ' Set Common Dialog Box flags here CommonDialog1.ShowOpen NameParts = Split(CommonDialog1.FileTitle & ".", ".") FilesName = NameParts(0) FilesExtension = NameParts(1) Rick "Rick Rothstein \(MVP - VB\)"
<rickNOSPAMnews@NOSPAMcomcast.net>'s wild thoughts were released on Mon, 26 Feb 2007 09:57:40 -0500 bearing the following fruit: Show quoteHide quote >> I need to determine file type from the file path and name Hmm..>> which I get from the CommonDialog control. > >As long as the cdlOFNNoValidate flag is NOT set (I can't think of any reason >it should be), you can use this code to get the file's name and extension... > > Dim FilesName As String > Dim FilesExtension As String > Dim NameParts() As String > ' Set Common Dialog Box flags here > CommonDialog1.ShowOpen > NameParts = Split(CommonDialog1.FileTitle & ".", ".") > FilesName = NameParts(0) > FilesExtension = NameParts(1) Jan.Hyde.txt I've come across a lot of documents like that > Hmm.. Picky...picky...picky <g>> > Jan.Hyde.txt > > I've come across a lot of documents like that Okay, so much for off the top of the head code. Well, let's try one more off the top of my head solution<g>... Dim FilesName As String Dim FilesExtension As String Dim NameParts() As String CommonDialog1.ShowOpen NameParts = Split(CommonDialog1.FileTitle, ".") If UBound(NameParts) Then FilesExtension = NameParts(UBound(NameParts)) ReDim Preserve NameParts(UBound(NameParts) - 1) End If FilesName = Trim$(Join(NameParts, ".")) I think this code works. Rick Thanks!
I'll try it, if no worky, I'll repost -- Show quoteHide quoteThank you, Randy "Rick Rothstein (MVP - VB)" wrote: > > Hmm.. > > > > Jan.Hyde.txt > > > > I've come across a lot of documents like that > > Picky...picky...picky <g> > > Okay, so much for off the top of the head code. Well, let's try one more off > the top of my head solution<g>... > > Dim FilesName As String > Dim FilesExtension As String > Dim NameParts() As String > CommonDialog1.ShowOpen > NameParts = Split(CommonDialog1.FileTitle, ".") > If UBound(NameParts) Then > FilesExtension = NameParts(UBound(NameParts)) > ReDim Preserve NameParts(UBound(NameParts) - 1) > End If > FilesName = Trim$(Join(NameParts, ".")) > > I think this code works. > > Rick > > >
Show quote
Hide quote
"Rick Rothstein \(MVP - VB\)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote What's wrong with a one-liner ?!?!?!!??.....in news:OsX8vRcWHHA.388@TK2MSFTNGP04.phx.gbl: >> Hmm.. >> >> Jan.Hyde.txt >> >> I've come across a lot of documents like that > > Picky...picky...picky <g> > > Okay, so much for off the top of the head code. Well, let's try one > more off the top of my head solution<g>... > > Dim FilesName As String > Dim FilesExtension As String > Dim NameParts() As String > CommonDialog1.ShowOpen > NameParts = Split(CommonDialog1.FileTitle, ".") > If UBound(NameParts) Then > FilesExtension = NameParts(UBound(NameParts)) > ReDim Preserve NameParts(UBound(NameParts) - 1) > End If > FilesName = Trim$(Join(NameParts, ".")) > > I think this code works. > > Rick > > FileName = mid$(CommonDialog1.FileTitle, _ InStrRev (CommonDialog1.FileTitle,"\") + 1) > What's wrong with a one-liner ?!?!?!!??..... Nothing is wrong with a one-liner, but do you realize that all of the code > > FileName = mid$(CommonDialog1.FileTitle, _ > InStrRev (CommonDialog1.FileTitle,"\") + 1) you have there produces the same result as this? FileName = CommonDialog1.FileTitle By the way, the question asked how to get the extension (I threw in the file name part as a bonus<g>). Rick
Show quote
Hide quote
"Rick Rothstein \(MVP - VB\)" <rickNOSPAMnews@NOSPAMcomcast.net> wrote DOH !!!!!!! I didn't notice you were using FileTitle from the comDlg in news:OpNjBlfWHHA.996@TK2MSFTNGP02.phx.gbl: >> What's wrong with a one-liner ?!?!?!!??..... >> >> FileName = mid$(CommonDialog1.FileTitle, _ >> InStrRev (CommonDialog1.FileTitle,"\") + 1) > > Nothing is wrong with a one-liner, but do you realize that all of the > code you have there produces the same result as this? > > FileName = CommonDialog1.FileTitle > control, and just blindly typed away. (I rarely use the comDlg.) > By the way, the question asked how to get the extension Then just change the "\" to "." in the code above and you have the extension only then. The (still a) one-liner would be.... Extension = mid$(CommonDialog1.FileTitle, _ InStrRev (CommonDialog1.FileTitle,".") + 1) Show quoteHide quote > (I threw in the file name part as a bonus<g>). > Rick "Rick Rothstein \(MVP - VB\)"
<rickNOSPAMnews@NOSPAMcomcast.net>'s wild thoughts were released on Mon, 26 Feb 2007 11:37:41 -0500 bearing the following fruit: >> Hmm.. I could have included my middle name>> >> Jan.Hyde.txt >> >> I've come across a lot of documents like that > >Picky...picky...picky <g> Jan.Pedantic.Hyde.txt ;-) J Show quoteHide quote >Okay, so much for off the top of the head code. Well, let's try one more off >the top of my head solution<g>... > > Dim FilesName As String > Dim FilesExtension As String > Dim NameParts() As String > CommonDialog1.ShowOpen > NameParts = Split(CommonDialog1.FileTitle, ".") > If UBound(NameParts) Then > FilesExtension = NameParts(UBound(NameParts)) > ReDim Preserve NameParts(UBound(NameParts) - 1) > End If > FilesName = Trim$(Join(NameParts, ".")) > >I think this code works. > >Rick >
Sad
Inline Assembly In VB6 Database connection problem on VB6.0 VB6 DLL Assembly Compile Link how??? How to open a CMD Line exe as hidden and wat for it to finish Have a problem that is stumping me. Problem populating a combobox if cases differ Interlocked Functions vs VB Reading Current Value Excel automation format textbox for ip-address. |
|||||||||||||||||||||||