No announcement yet.

Browse for files & put file path(s) in edit field

  • Filter
  • Time
  • Show
Clear All
new posts

    Browse for files & put file path(s) in edit field

    OK, so in my program I have 2 browse buttons and two edit fields
    How can I browse for any file or application and put the file path in my edit fields? When the first browse button is pressed the first path would go into the first edit field, when the second browse button is pressed the second path would go into the second edit field.
    Brian Heibert
    [email protected]

    look up OpenFileDialog using the search facility in these forums.


      Found this code but still got a question


      I found this code in the forums how can I modify it to select any file?
      Document or Application? and put the file path in a edit field?

      LOCAL buf, spath, sfile AS STRING
      LOCAL dwstyle AS DWORD
      LOCAL hFile AS LONG
      Buf = "Picture files (*.JPG)|*.JPG|"
      'IF gddlpath <> "" THEN spath = gddlpath
      IF OpenFileDialog (hD, "Locate JPG file ", sfile, spath, buf, "JPG", dwstyle) = 0 THEN
      END IF
      FUNCTION = sfile
      Brian Heibert
      [email protected]


        Ok I will bite

        What is it you are trying to achieve?
        • Select 1 file, copy to another path?
        • Select 2 files? (one from each button?)
        • Select 2 or more files? (from one button?)
        • Something else???

        Impossible to guess from the details shown, but if you can elaborate, I am sure 1 if not more of us can point you more to the concept you are searching
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "


          OK I will have two path edit fields with two browse buttons

          I want to select 1 file or application and put the path in the first edit field

          then select another file or application and put the path in the second edit field.

          That is all I need help with so far.

          I did this in REALbasic on the Mac. I'd use REALbasic for Windows, but I don't have a license as of yet, and I happen to have a PB license.
          Brian Heibert
          [email protected]


            If you have 9.0:
            In the dialog´s CALLBACK FUNCTION in the separate cases for each "browse button" when clicked.
            Use DISPLAY OPENFILE to get the path\filename to your "filename$" variable.
            Then assign to the edit box using CONTROL ADD TEXT where the string is derived by the PATHNAME$(director, filespec$) function. In pseudo-code:
            CASE %WM_COMMAND
                    SELECT CASE AS LONG CB.CTL
                           CASE %IDC_BTN_BROWSE1
                                IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                                       DISPLAY OPENFILE 0, , , "",CURDIR$ , "", _
                                             "*.*", "", %OFN_ENABLESIZING OR _
                                            %OFN_FILEMUSTEXIST OR %OFN_PATHMUSTEXIST OR _
                                            %OFN_EXPLORER TO PFN1$
                                      CONTROL ADD TEXT CB.HNDL, %IDC_EDIT1, PATHNAME$(PATH,PFN1$)
                                END IF
            Rick Angell


              For PBWin8..

              #COMPILE EXE
              #INCLUDE ""
              #INCLUDE ""
              FUNCTION GetFileName(ByVal sNumber AS STRING) AS STRING 
               LOCAL sPath, sFilter, sChoice, sMsg AS STRING 
               LOCAL dwStyle AS Dword 
                sChoice  = " "
                sPath    = CURDIR$
                sFilter  = "All Files (*.*)|*.*|Text files (*.txt)|*.txt"   ' | => "+$NUL+" in
                dwStyle  = %OFN_FILEMUSTEXIST OR %OFN_EXPLORER
                IF OpenFileDialog (0, _                                     ' Call function in
                                   "Select file number:" + sNumber, _
                                   sChoice, _
                                   sPath, _
                                   sFilter, _
                                   "", _
                                   dwStyle) THEN 
                  sMsg = sChoice
                  sMsg = sMsg + $CRLF + "File:" + $TAB + Right$(sChoice, - INSTR(-1, sChoice, ANY "\/"))
                  sMsg = sMsg + $CRLF + "Path:" + $TAB + Left$(sChoice, INSTR(-1, sChoice, ANY "\/"))
                  MsgBox sMsg, %MB_SYSTEMMODAL, "File Selected"
                  MSGBOX "No selection made!",%MB_SYSTEMMODAL , "OpenFileDialog"
                END If 
                FUNCTION = sChoice
              END FUNCTION
              CallBack Function DlgProc()
               LOCAL sChoice, sTemp AS STRING, n AS LONG 
                SELECT CASE AS LONG CbMsg
                  CASE %WM_COMMAND
                    SELECT Case As Long CbCtl
                      CASE %IDC_BUTTON1
                        IF CbCtlMsg = %BN_CLICKED THEN
                         sChoice = GetFileName("1")
                         CONTROL SET TEXT hDlg, %IDC_TEXTBOX1, sChoice
                        END IF
                      'CASE %IDC_BUTTON2  'repeat for GetFileName("2")
                      CASE %IDC_BUTTON3
                        IF CbCtlMsg = %BN_CLICKED THEN
                          CONTROL GET TEXT CbHndl, %IDC_TEXTBOXn To sTemp
                          'use sTemp...etc
                        END IF
                    END SELECT
                END SELECT
              END FUNCTION 
              FUNCTION PBMain() AS Long 
               'DIALOG NEW... to hDlg
                'CONTROL ADD TEXTBOX...
                'CONTROL ADD BUTTON....
               'DIALOG SHOW MODAL hDlg, CALL DlgProc
              END FUNCTION
              Last edited by Dave Biggs; 4 Nov 2008, 10:55 AM.
              Rgds, Dave


                Brian only wants the path, so a change to the 8.0 example, changing:

                FUNCTION = sChoice

                FUNCTION = Left$(sChoice, INSTR(-1, sChoice, ANY "\/"))
                Rick Angell


                  Thankyou, I have 8.0

                  I will look at these tonight.
                  Got to go to work now

                  Brian Heibert
                  [email protected]


                    I've consolidated into one function, set the last parameter %TRUE for save_as and %FALSE for OPEN.
                    sTmp is returned as the filename, if it has LEN(sTMp) then control set text it onto your edit control.

                                  lResult = CCSFileDialog(ByVal CbHndl, _  ' parent window
                                            ByVal "Open File", _            ' caption
                                            sTmp, _                      ' filename
                                            WorkingDir , _                  ' start directory
                                            ByVal sFilter, _                ' filename filter
                                            "Ini", _                        ' wDefault extension
                                            %OFN_OVERWRITEPROMPT Or %OFN_EXPLORER, _                            ' flags
                                            %FALSE)                         ' Type of Dialog
                                  If IsFalse lResult Or IsFalse Len(sTmp) Then
                                      Exit Function
                                      g_IniFile = sTmp
                                      sTmp = g_szMine & " - " & g_szVer & " - " & g_IniFile
                                      SetWindowText ByVal CbHndl,ByVal StrPtr(sTmp)
                                  End If
                                  If IsTrue Exist(ByVal g_IniFile) Then
                                      lResult = LoadIniFile()
                                      Exit Function
                                  End If   
                    Function CCSFileDialog(ByVal hWnd As Long, _                ' parent window
                                           ByVal Caption As String, _           ' caption
                                           Filespec As String, _                ' filename
                                           ByVal InitialDir As String, _        ' start directory
                                           ByVal Filter As String, _            ' filename filter
                                           ByVal DefExtension As String, _      ' wDefault extension
                                           Flags As Long, _                     ' flags
                                           TypeOfDialog As Long)  As Long         ' SaveAs or Open?
                      Local Ofn           As OPENFILENAME
                      Local zFile         As Asciiz * 256
                      Local zFileTitle    As Asciiz * 256
                      Local zFilter       As Asciiz * 256
                      Local zInitialDir   As Asciiz * 256
                      Local zTitle        As Asciiz * 256
                      Local zDefExt       As Asciiz * 10
                      Replace "|" With Chr$(0) In Filter
                      Filter = Filter & Chr$(0)
                      If Len(InitialDir) = 0 Then
                        InitialDir = CurDir$
                      End If
                      zFilter     = Filter + Chr$(0)
                      zInitialDir = InitialDir + Chr$(0)
                      zFile       = Filespec + Chr$(0)
                      zDefExt     = DefExtension + Chr$(0)
                      zTitle      = Caption + Chr$(0)
                      ofn.lStructSize       = SizeOf(ofn)
                      ofn.hWndOwner         = hWnd
                      ofn.lpstrFilter       = VarPtr(zFilter)
                      ofn.nFilterIndex      = 1
                      ofn.lpstrFile         = VarPtr(zFile)
                      ofn.nMaxFile          = SizeOf(zFile)
                      ofn.lpstrFileTitle    = VarPtr(zFileTitle)
                      ofn.nMaxFileTitle     = SizeOf(zFileTitle)
                      ofn.lpstrInitialDir   = VarPtr(zInitialDir)
                      If Len(zTitle) Then
                        ofn.lpstrTitle        = VarPtr(zTitle)
                      End If
                      ofn.Flags             = Flags
                      ofn.lpstrDefExt       = VarPtr(zDefExt)
                      If IsTrue TypeOfDialog Then
                          Function = GetSaveFilename(ofn)
                          Function = GetOpenFilename(ofn)
                      End If
                      InitialDir = CurDir$
                      Filespec = zFile
                      Flags    = ofn.Flags
                    End Function
                    Scott Turchin
                    MCSE, MCP+I
                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi