Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scott Turchin
    replied
    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.

    Code:
                  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
                  Else
                      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()
                  Else
                      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)
      Else
          Function = GetOpenFilename(ofn)
      End If
    
    
      InitialDir = CurDir$
      Filespec = zFile
      Flags    = ofn.Flags
    
    End Function

    Leave a comment:


  • Brian Heibert
    replied
    Thankyou, I have 8.0

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

    Brian

    Leave a comment:


  • Richard Angell
    replied
    Brian only wants the path, so a change to the 8.0 example, changing:

    Code:
    FUNCTION = sChoice
    to:

    Code:
    FUNCTION = Left$(sChoice, INSTR(-1, sChoice, ANY "\/"))

    Leave a comment:


  • Dave Biggs
    replied
    For PBWin8..

    Code:
    #COMPILE EXE
    #INCLUDE "Win32api.inc"
    #INCLUDE "ComDlg32.inc"
     
    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 ComDlg32.inc
      dwStyle  = %OFN_FILEMUSTEXIST OR %OFN_EXPLORER
     
      IF OpenFileDialog (0, _                                     ' Call function in ComDlg32.inc
                         "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"
      ELSE
        MSGBOX "No selection made!",%MB_SYSTEMMODAL , "OpenFileDialog"
      END If 
     
      FUNCTION = sChoice
    END FUNCTION
    '------------------/GetFileName
     
    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 
    '------------------/DlgProc
     
    FUNCTION PBMain() AS Long 
     
     'DIALOG NEW... to hDlg
      'CONTROL ADD TEXTBOX...
      'CONTROL ADD BUTTON....
      'etc
     
     'DIALOG SHOW MODAL hDlg, CALL DlgProc
     
    END FUNCTION
    '------------------/PBMain
    Last edited by Dave Biggs; 4 Nov 2008, 10:55 AM.

    Leave a comment:


  • Richard Angell
    replied
    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:
    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

    Leave a comment:


  • Brian Heibert
    replied
    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.

    Leave a comment:


  • Cliff Nichols
    replied
    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

    Leave a comment:


  • Brian Heibert
    replied
    Found this code but still got a question

    Hi,

    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
    dwStyle = %OFN_EXPLORER OR %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY
    Buf = "Picture files (*.JPG)|*.JPG|"
    'IF gddlpath <> "" THEN spath = gddlpath
    IF OpenFileDialog (hD, "Locate JPG file ", sfile, spath, buf, "JPG", dwstyle) = 0 THEN
    EXIT FUNCTION
    END IF
    FUNCTION = sfile

    Leave a comment:


  • Chris Holbrook
    replied
    look up OpenFileDialog using the search facility in these forums.

    Leave a comment:


  • 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.
Working...
X
😀
🥰
🤢
😎
😡
👍
👎