Solved

getting path

Posted on 2000-05-02
9
201 Views
Last Modified: 2010-05-02
Hi all,
I would like to know, is there any function just like "GETDIR()" in Visual Fox Pro, which let users to choose path and return the path as a string?

Thanks!
0
Comment
Question by:chuyan
  • 2
  • 2
  • 2
  • +3
9 Comments
 

Expert Comment

by:wnchan
ID: 2768545
Yes, there ia a function for user to choose path and return the path as string. the function is Dir().
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2768635
dear wnchan: Dir() doesn't allow the user CHOOSE a path, but return the current path

I think what chuyan needs is a dialog box to Open/Save a File.
In this case, you can use the Common Dialog Control (look in components)

Hope this helps
0
 

Author Comment

by:chuyan
ID: 2769925
yup, I think angelIII knows what  I need.  But I'm not sure that if common dialog box works.  Since I only want to let users to choose the directories only, I don't  want to let them input anything by typing.  I just want them to select their desired directory.  Could the common dialog box help?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2769940
In this case, not really.
You would need to implement your own dialog box using the drive control and the directory control and some buttons;
or try to find a free dialog box on sites like www.vbcontrol.com or www.vbaccelerator.com
Hope this helps
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2774212
use the dirlistbox control that is in your toolbox, to see how it works stick a dirlistbox on your form and a textbox and paste this code:

Private Sub Dir1_Change()
    Text1.Text = Dir1.Path
End Sub

0
 

Expert Comment

by:syedAliF
ID: 2776572
To try this example you need to add a textbox , commondialog control and a command button.
add this code in the form and run

Private Sub Command1_Click()
CommonDialog1.ShowOpen
Text1 = CommonDialog1.FileName
End Sub

text1 will contain the path of the file which the user has chosen by clicking the command button.
Hope this will help you.
bye.
0
 

Accepted Solution

by:
swoosh72 earned 10 total points
ID: 2777823
I'm not sure if I understand correctly what you are looking for, but try this.
Create a new VB Project.
Under the project menu click components. When the box loads, scroll down to find one called Microsoft Common Dialog Control. Check this option and click ok. It's now listed in your toolbox as a small window icon.

Add one to your form.

Once this is done, add the following code to your form's (General) (Declaration) section.



Option Explicit
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260


Private Declare Function SHBrowseForFolder Lib _
        "shell32" (lpbi As 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 Type 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


Now add a command button to your form.
Make sure it's named Command1

Copy the following code into the Command1 Click event.
    '     displays the
    'directories in your computer
    Dim lpIDList As Long ' Declare Varibles
    Dim sBuffer As String
    Dim szTitle As String
    Dim tBrowseInfo As BrowseInfo
    szTitle = "Hello World. Click On a directory and " & _
        "it's path will be displayed In a message box"
    ' Text to appear in the the gray area un
    '     der the title bar
    ' telling you what to do


    With tBrowseInfo
            .hWndOwner = Me.hWnd ' Owner Form
            .lpszTitle = lstrcat(szTitle, "")
            .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
    End With
    lpIDList = SHBrowseForFolder(tBrowseInfo)


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


Run the program and click the button.
You will be prompted with a browse for folder box and you will it will return it's path. Let me know how it works out.

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2777847
swoosh welcome to EE. it is customary to just post comments here.  the questioner can accept a comment as an answer at any time.
0
 

Expert Comment

by:swoosh72
ID: 2777874
Thanks dude. I'm new here and I appreciate the tip.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now