looking / storing working directory 
Author Message
 looking / storing working directory

How do you setup VB to look for a working directory ?  The app may be in one
drive/directory and the data may be in another location. When my application
starts I would like it to point to the correct data location. Is it best to
store that information in a ini file ? Any samples available on the web ?

Thanks in advance.

--
David L. Koup
General Manager
Koup's Cycle Shop Inc.
"The Good Times Store"
http://www.*-*-*.com/
"Kawasaki" "Suzuki" "Ducati" "Moto Guzzi"
Established 1957
"Dealer News Magazine Top 100 Dealer"



Fri, 19 Jan 2001 03:00:00 GMT  
 looking / storing working directory
Hi, Dave.

You could store it in an .ini, .txt or .dat file, probably several others.
Even a file without an extension. Give the user the choice to set where the
data is to be saved by using the "browse for folder" common dialogue. Store
the returned path in a file. Here's some code :

Paste this into your form, using a command button called cmdChange to call
the Browse Dialogue. Add a textbox to your form, called txtDataLocation, to
display to the user where his data is going. You can of course change the
names of the command button, textbox and the settings.ini to anything you
want.

'***********Begin Paste***********

Private Sub cmdChange_Click()
Dim bi As BROWSEINFO
Dim FileNum
Dim nFolder As Long
Dim IDL As ITEMIDLIST
Dim pIdl As Long
With bi
nFolder = 17

If SHGetSpecialFolderLocation(ByVal Me.hWnd, ByVal nFolder, IDL) = NOERROR
Then
 .pidlRoot = IDL.mkid.cb
 End If

 .lpszTitle = "Enter some text here to explain this function."

.ulFlags = BIF_RETURNONLYFSDIRS

End With

pIdl = SHBrowseForFolder(bi)
If pIdl = 0 Then
   Exit Sub
   End If

sPath = String$(MAX_PATH, 0)
SHGetPathFromIDList ByVal pIdl, ByVal sPath

' This is the location that was selected

txtDataLocation = sPath

CoTaskMemFree pIdl

'This part write the location selected to a file
'called setings.ini which needs to be in the
'same location as your App

FileNum = FreeFile
   Open "settings.ini" For Output As FileNum
   Write #FileNum, txtDataLocation.Text
   Close FileNum

End Sub

'**************End Paste********

Add a new module and paste the following in :

'**********Begin Paste*************

Option Explicit
Type SHITEMID
    cb As Long
    abID() As Byte
End Type
Type ITEMIDLIST
    mkid As SHITEMID
End Type
Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias
"SHGetPathFromIDListA" _
                              (ByVal pIdl As Long, ByVal pszPath As String)
As Long
Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
                              (ByVal hwndOwner As Long, ByVal nFolder As
Long, _
                              pIdl As ITEMIDLIST) As Long
Public Const NOERROR = 0
Public Const CSIDL_DESKTOP = &H0
Public Const CSIDL_PROGRAMS = &H2
Public Const CSIDL_CONTROLS = &H3
Public Const CSIDL_PRINTERS = &H4
Public Const CSIDL_PERSONAL = &H5
Public Const CSIDL_FAVORITES = &H6
Public Const CSIDL_STARTUP = &H7
Public Const CSIDL_RECENT = &H8
Public Const CSIDL_SENDTO = &H9
Public Const CSIDL_BITBUCKET = &HA
Public Const CSIDL_STARTMENU = &HB
Public Const CSIDL_DESKTOPDIRECTORY = &H10
Public Const CSIDL_DRIVES = &H11
Public Const CSIDL_NETWORK = &H12
Public Const CSIDL_NETHOOD = &H13
Public Const CSIDL_FONTS = &H14
Public Const CSIDL_TEMPLATES = &H15
Public Const MAX_BROWSEPATH = 260
Public sPath As String

Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias
"SHBrowseForFolderA" _
                              (lpBrowseInfo As BROWSEINFO) As Long

Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Public Const BIF_RETURNONLYFSDIRS = &H1
Public Const BIF_DONTGOBELOWDOMAIN = &H2
Public Const BIF_STATUSTEXT = &H4
Public Const BIF_RETURNFSANCESTORS = &H8
Public Const BIF_BROWSEFORCOMPUTER = &H1000
Public Const BIF_BROWSEFORPRINTER = &H2000

'*********End Paste*********
--

Regards, Paul.

IE4 Assistant Forum Manager



Quote:

>How do you setup VB to look for a working directory ?  The app may be in
one
>drive/directory and the data may be in another location. When my
application
>starts I would like it to point to the correct data location. Is it best to
>store that information in a ini file ? Any samples available on the web ?

>Thanks in advance.

>--
>David L. Koup
>General Manager
>Koup's Cycle Shop Inc.
>"The Good Times Store"
>http://www.koups.com
>"Kawasaki" "Suzuki" "Ducati" "Moto Guzzi"
>Established 1957
>"Dealer News Magazine Top 100 Dealer"



Sat, 20 Jan 2001 03:00:00 GMT  
 looking / storing working directory
Dave...

I prefer to store working directory paths in the registry:

    SaveSetting "MyProgram", "Paths", "Reports", "C:\DATA\REPORTS\"
    SaveSetting "MyProgram", "Paths", "Images", "C:\DATA\IMAGES\"
    SaveSetting "MyProgram", "Options", "AllowDelete", True

Retrieval is just as easy:

    NewPath = GetSetting("MyProgram","Paths","Reports","C:\")

(The last parameter is the default value to use in case one is not found in the
registry)
Hope this helps-
                                                Matt Lebeau, Research Genetics

Quote:

> How do you setup VB to look for a working directory ?  The app may be in one
> drive/directory and the data may be in another location. When my application
> starts I would like it to point to the correct data location. Is it best to
> store that information in a ini file ? Any samples available on the web ?

> Thanks in advance.

> --
> David L. Koup
> General Manager
> Koup's Cycle Shop Inc.
> "The Good Times Store"
> http://www.koups.com
> "Kawasaki" "Suzuki" "Ducati" "Moto Guzzi"
> Established 1957
> "Dealer News Magazine Top 100 Dealer"



Sat, 20 Jan 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. looking / storing working directory

2. Looking for a function to check all sub directory

3. Looking for a Replacement Folder/Directory List Box

4. Looking For Multiple Directory Selection OCX

5. Better looking Drive and Directory Controls

6. Looking into a directory....

7. looks for OCX in wrong directory

8. Looking for a control to navigate through directory tree

9. Looking For 3rd Party Directory List Box Control

10. Looking for Directory List Control w/Network Browsing capability

11. Looking for better way of getting directory names(searching disks)

12. looking for some File & directory functions

 

 
Powered by phpBB® Forum Software