From: theBlueFox on
Gentlemen & Women,

I am trying to assign a file path (with out the file name) to a variable and
am having some difficulty using the common dialog. For example...


I have a variable strTest

I want it to contain the path c:\job\new
Not c:\job\new\somename.doc

so that ...

strTest = "c:\job\new"

Can I do this with the common dialog, or is it a different control? thanks.


-ps


From: Jeff Johnson on
"theBlueFox" <my(a)email.usa> wrote in message
news:ufwvStE%23KHA.4652(a)TK2MSFTNGP06.phx.gbl...

> I am trying to assign a file path (with out the file name) to a variable
> and am having some difficulty using the common dialog. For example...
>
>
> I have a variable strTest
>
> I want it to contain the path c:\job\new
> Not c:\job\new\somename.doc
>
> so that ...
>
> strTest = "c:\job\new"
>
> Can I do this with the common dialog, or is it a different control?
> thanks.

You want a FolderBrowser dialog. You can search this group on Google for
"folder browser dialog" or go to http://ccrp.mvps.org/ and get the
BrowseDialog control or server. (I recommend the server.)


From: theBlueFox on
Thanks Jeff, must be the fastest response I ever had!

Regards
"Jeff Johnson" <i.get(a)enough.spam> wrote in message
news:uaglSxE%23KHA.1892(a)TK2MSFTNGP05.phx.gbl...
> "theBlueFox" <my(a)email.usa> wrote in message
> news:ufwvStE%23KHA.4652(a)TK2MSFTNGP06.phx.gbl...
>
>> I am trying to assign a file path (with out the file name) to a variable
>> and am having some difficulty using the common dialog. For example...
>>
>>
>> I have a variable strTest
>>
>> I want it to contain the path c:\job\new
>> Not c:\job\new\somename.doc
>>
>> so that ...
>>
>> strTest = "c:\job\new"
>>
>> Can I do this with the common dialog, or is it a different control?
>> thanks.
>
> You want a FolderBrowser dialog. You can search this group on Google for
> "folder browser dialog" or go to http://ccrp.mvps.org/ and get the
> BrowseDialog control or server. (I recommend the server.)
>


From: Jeff Johnson on
"theBlueFox" <my(a)email.usa> wrote in message
news:e5MtB0E%23KHA.3580(a)TK2MSFTNGP06.phx.gbl...

> Thanks Jeff, must be the fastest response I ever had!

Ehhh, 7 minute gap. I've been faster....


From: DanS on
"theBlueFox" <my(a)email.usa> wrote in
news:ufwvStE#KHA.4652(a)TK2MSFTNGP06.phx.gbl:

> Gentlemen & Women,
>
> I am trying to assign a file path (with out the file name)
> to a variable and am having some difficulty using the
> common dialog. For example...
>
>
> I have a variable strTest
>
> I want it to contain the path c:\job\new
> Not c:\job\new\somename.doc
>
> so that ...
>
> strTest = "c:\job\new"
>
> Can I do this with the common dialog, or is it a different
> control? thanks.
>
>
> -ps

Here's a class to do BrowseFroFile and BrowseForFolder....all
API and no added dependencies (dll or ocx).

I don't know where I got this from.

Just copy & paste the code below in a new class, instantiate
an instance when necessary, then kill it. (I'm sure you'll
need to fix the wrapping.)

-------------------------------------------------------
Option Explicit

'Constants
Private Const BIF_RETURNONLYFSDIRS = &H1 'Uniquement
des répertoire
Private Const BIF_DONTGOBELOWDOMAIN = &H2 'Domaine
globale intredit
Private Const BIF_STATUSTEXT = &H4 'Zone de
saisie autorisée
Private Const BIF_RETURNFSANCESTORS = &H8
Private Const BIF_EDITBOX = &H10 'Zone de
saisie autorisée
Private Const BIF_VALIDATE = &H20 'insist on
valid result (or CANCEL)
Private Const BIF_BROWSEFORCOMPUTER = &H1000 'Uniquement
des PCs.
Private Const BIF_BROWSEFORPRINTER = &H2000 'Uniquement
des imprimantes
Private Const BIF_BROWSEINCLUDEFILES = &H4000 'Browsing for
Everything
Private Const MAX_PATH = 1024
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_ENABLEHOOK = &H20
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_LONGNAMES = &H200000
' force long names for 3.x modules

'Types
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Private Type T_BROWSEINFO
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

'Functions API Windows
Private Declare Function SHBrowseForFolder Lib "shell32" _
(lpbi As T_BROWSEINFO) As
Long
Private Declare Function SHGetPathFromIDList Lib "shell32" _
(ByVal pidList As Long, _
ByVal lpBuffer As String) As
Long
Private Declare Function lstrcat Lib "kernel32" Alias
"lstrcatA" _
(ByVal lpString1 As String,
ByVal _
lpString2 As String) As Long

Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long

Public Property Get BrowseFolder(hwndOwner As Long, DlgTitle
As String) As String
Dim lpIDList As Long
Dim sBuffer As String
Dim BrowseInfo As T_BROWSEINFO

'Initialise
BrowseFolder = ""

With BrowseInfo
.hwndOwner = hwndOwner
.lpszTitle = lstrcat(DlgTitle, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With

lpIDList = SHBrowseForFolder(BrowseInfo)

If (lpIDList) Then
sBuffer = Space(MAX_PATH)
SHGetPathFromIDList lpIDList, sBuffer
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
BrowseFolder = sBuffer
End If
End Property

Public Property Get StripFileName(SrcStr As String) As String
Dim Idx As Long
Dim LastIdx As Long
Dim TotalBytes As Long

StripFileName = ""

Idx = 1
TotalBytes = 0
Idx = InStr(Idx, SrcStr, "\")

While (Idx > 0)
LastIdx = Idx
Idx = InStr(LastIdx + 1, SrcStr, "\")
Wend

If (LastIdx <> 0) Then
StripFileName = Mid(SrcStr, 1, LastIdx - 1)
End If
End Property

Public Property Get BrowseForFile(hwnd As Long, filter As
String, Optional initDir As String) As String
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Dim Idx As Long

' Change pipes into nulls
' the ocx uses pipes for its filters the api uses nulls.
' api is fast and less overhead.
Idx = InStr(1, filter, "|")
While (Idx <> 0)
filter = Mid(filter, 1, Idx - 1) & Chr(0) & Mid(filter,
Idx + 1, Len(filter) - Idx)
Idx = InStr(1, filter, "|")
Wend

filter = filter & Chr(0)
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = hwnd
OpenFile.hInstance = App.hInstance
sFilter = filter
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
If Len(initDir) Then
OpenFile.lpstrInitialDir = initDir
Else
OpenFile.lpstrInitialDir = App.Path
End If
OpenFile.lpstrTitle = "Find Source File"
OpenFile.flags = OFN_FILEMUSTEXIST
'OpenFile.lpstrInitialDir =

lReturn = GetOpenFileName(OpenFile)

If lReturn <> 0 Then
Dim tStr As String
Dim x As Long
tStr = Trim(OpenFile.lpstrFile)
For x = 1 To Len(tStr)
If Asc(Mid$(tStr, x, 1)) > 0 Then
BrowseForFile = BrowseForFile & Mid$(tStr, x,
1)
Else
Exit For
End If
Next
End If
End Property

Public Property Get GetFileName(SrcStr As String) As String
Dim Idx As Long
Dim LastIdx As Long
Dim TotalBytes As Long

GetFileName = ""

Idx = 1
TotalBytes = 0
Idx = InStr(Idx, SrcStr, "\")

While (Idx > 0)
LastIdx = Idx
Idx = InStr(LastIdx + 1, SrcStr, "\")
Wend

If (LastIdx <> 0) Then
GetFileName = Mid(SrcStr, LastIdx + 1, Len(SrcStr) - Idx -
1)
End If
End Property