Hey Guys !
Is thr any1 who can help me in this problem ? I need a code
that will extract the shortenfilenam (only the filename)
from a total string passed by the commondialog ?
emranHASAN
Printable View
Hey Guys !
Is thr any1 who can help me in this problem ? I need a code
that will extract the shortenfilenam (only the filename)
from a total string passed by the commondialog ?
emranHASAN
This is the code used to get the effect that is used by Notepad. It might help.
Code:frmMain.Caption = "" & CommonDialog1.FileTitle & " - Notepad"
Code:Option Explicit
Private Sub Command1_Click()
CommonDialog1.InitDir = "C:\" 'set dir path
CommonDialog1.CancelError = True 'used in cancel code
CommonDialog1.Filter = "All files(*.*)|*.*" 'filter for all files
CommonDialog1.ShowOpen 'show files
MsgBox CommonDialog1.FileTitle
'if you don't want the extension
Dim myLen As Integer
myLen = Len(CommonDialog1.FileTitle)
MsgBox Left(CommonDialog1.FileTitle, myLen - 4)
End Sub
Thats basicly the same as what i have just said
This will only work if the length of the extension is 3 chars. It will not work with .jpeg or .html files.Quote:
Originally posted by HeSaidJoe
Code:MsgBox Left(CommonDialog1.FileTitle, myLen - 4)
Electroman:
How Notepad does it
This is the code used to get the effect that is used by Notepad. It might help.
I was merely pointing out that it is not specific to notepad and giving the commondialog code to do so.
Oetje:
Will put a fix for that in a moment.
Code:'Corrected Version
Option Explicit
Private Sub Command1_Click()
CommonDialog1.InitDir = "C:\" 'set dir path
CommonDialog1.CancelError = True 'used in cancel code
CommonDialog1.Filter = "All files(*.*)|*.*" 'filter for all files
CommonDialog1.ShowOpen 'show files
MsgBox CommonDialog1.FileTitle
Dim SearchString, SearchChar, MyPos
SearchString = CommonDialog1.FileTitle ' String to search in.
SearchChar = "." ' Search for "."
MyPos = InStr(1, SearchString, SearchChar, 1)
'if found MyPos will be > 0
If MyPos > 0 Then
MsgBox Left(CommonDialog1.FileTitle, MyPos - 1)
End If
End Sub