Multiple file select via DoBrowse property in MSButton?

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

Multiple file select via DoBrowse property in MSButton?

Post by strosfan47 » Tue Feb 15, 2011 3:36 pm

Hi, how to I alter the below DoBrowse code to enable multiple file select? Selecting one file at a time won't work for my app.

I've scoured all available resources (including: http://www.mjtnet.com/OnlineHelp/index. ... bjects.htm), and think I am missing something vital. Thanks in advance!

Code: Select all

AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse


Show>Dialog1,result

SRT>DoBrowse
  //set DoBrowse property to true
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True

  //get property Filename and assign value to strFileName
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName

  //asssign value of strFileName to property Text??
  SetDialogProperty>Dialog1,Edit1,Text,strFileName

  ReadFile>strFileName,strFileData
  SetDialogProperty>Dialog1,MSMemo1,Text,strFileData

END>DoBrowse
-- Bopert in Austin

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Tue Feb 15, 2011 9:20 pm

I don't think you can. (I am sure one of the guru's will correct me!)

Is this selecting files from a specific location?
Could you get the list of files and show it in a ListBox and allow multi select that way?

Not perfect but maybe a work around...
Thanks,
Jerry

[email protected]

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Feb 16, 2011 10:37 am

At present, no, there's no property to set the file open dialog to be multi-select. We'll add one in the next release.

In the mean time as Jerry says, you could make your own using GetFileList and a list box (see my reply to your other thread).

Or, if you have ComCtrl.OCX on your system (if not you should be able to google it) you can do this:

Code: Select all

VBSTART
Function MyFileBrowse(InitialDir,Filter)
  Dim objDialog
  Set objDialog = CreateObject("MSComDlg.CommonDialog")
  With objDialog
      .Filter = Filter
      .InitDir = InitialDir
      .MaxFileSize = 256
      .Flags = &H80000 + &H4 + &H8 + &H200 + &H200000
      '.Flags = &H200
      .ShowOpen
  End With

  Dim S
  Dim Strings
  Strings = Split(objDialog.FileName,chr(0))
  For i = 0 to UBound(Strings)
    S = S & Strings(i) & chr(13) & chr(10)
  Next
  MyFileBrowse = S
  Set objDialog = Nothing
End Function
VBEND

Dialog>Dialog1
object Dialog1: TForm
  Left = 701
  Top = 328
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 179
  ClientWidth = 333
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 227
    Top = 14
    Width = 75
    Height = 27
    Caption = 'Browse'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSMemo1: tMSMemo
    Left = 15
    Top = 14
    Width = 194
    Height = 147
    Lines.Strings = (
      'MSMemo1')
    TabOrder = 9
    Text = 'MSMemo1'
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSButton1,OnClick,BrowseIt

Show>Dialog1,r

SRT>BrowseIt
  VBEval>MyFileBrowse("%SCRIPT_DIR%","Text Files|*.txt"),selected_files
  SetDialogProperty>Dialog1,MSMemo1,Text,selected_files
  //you'd actually want to do some parsing here to parse out each file returned - in this example each file name is returned in a list delimited by CRLF with the folder path as the first item
END>BrowseIt
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Mar 30, 2011 1:47 pm

I could not get ComCtrl.OCX working on my computer. and according to THIS Microsoft page a license for Visual Basic or Visual Studio is required. I have a need for multi-browse today so I made a script per Jerry's suggestion. Could be made much fancier but this works.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 583
  Top = 208
  BorderIcons = [biSystemMenu]
  Caption = 'Select'
  ClientHeight = 470
  ClientWidth = 765
  object MSButton1: tMSButton
    Left = 686
    Top = 4
    Width = 75
    Height = 21
    Caption = 'Browse'
    TabOrder = 0
  end
  object MSButton2: tMSButton
    Left = 686
    Top = 445
    Width = 75
    Height = 21
    Caption = 'Process'
    TabOrder = 1
  end
  object Edit1: TEdit
    Left = 4
    Top = 4
    Width = 680
    Height = 21
    TabOrder = 2
  end
  object MSListBox1: tMSListBox
    Left = 4
    Top = 25
    Width = 680
    Height = 441
    TabOrder = 3
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,Process

SRT>DoBrowse
SetDialogProperty>Dialog1,MSListBox1,MultiSelect,True
  SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbFolder
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFolderName
  SetDialogProperty>Dialog1,Edit1,Text,strFolderName
  GetFileList>%strFolderName%\*.*,strFileList,CRLF
  StringReplace>strFileList,%strFolderName%\,,strFileList
  SetDialogProperty>Dialog1,MSListBox1,Text,strFileList
END>DoBrowse

SRT>Process
  GetDialogProperty>Dialog1,MSListBox1,SelectedItems,strFiles
  Let>MSG_WIDTH=600
  Let>MSG_HEIGHT=400
  MDL>Selected Folder:%CRLF%%strFolderName%\%CRLF%%CRLF%Selected Files:%CRLF%%strFiles%
END>Process

Show>Dialog1,res1

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Apr 14, 2011 10:04 pm

Here's a fancier version. Single click in the browse window to get to your location then double click on the desired location. Files in the double clicked folder should display in the list box on the right. Use the mouse with ctrl and shift to select multiple files. Pick the "process" button to work with the selection.

Code: Select all

OnEvent>Key_Down,VK1,0,Click
Let>ClickFlag=0
Let>DataCount=0
Let>strFolderName=C:\

Dialog>Dialog5
object Dialog5: TForm
  AutoSize = True
  BorderStyle = bsNone
  FormStyle = fsStayOnTop
  object MSImage1: tMSImage
    AutoSize = True
  end
end
EndDialog>Dialog5

Dialog>Dialog1
object Dialog1: TForm
  Caption = 'Select'
  ClientHeight = 470
  ClientWidth = 1099
  Position = poScreenCenter
  object PButton: tMSButton
    Left = 1014
    Top = 445
    Width = 75
    Height = 21
    Caption = 'Process'
  end
  object Edit1: TEdit
    Left = 332
    Top = 4
    Width = 680
    Height = 21
  end
  object MSListBox1: tMSListBox
    Left = 332
    Top = 25
    Width = 680
    Height = 441
  end
end
EndDialog>Dialog1

GoSub>MakeBrowserDialog
AddDialogHandler>Dialog1,PButton,OnClick,Process
AddDialogHandler>Dialog1,,OnClose,Quit
Show>Dialog1

Label>Loop
  Wait>0.01
  If>ClickFlag>0
    Add>ClickFlag,1
    If>ClickFlag>10
      Let>ClickFlag=0
      DeleteFile>%temp_dir%BrowserDialog.txt
    EndIf
  EndIf
Goto>Loop

SRT>Quit
  Exit>0
END>Quit

SRT>Click
  Let>WIN_USEHANDLE=1
  GetActiveWindow>title,winx,winY
  If>Title=ExpTitle
    If>ClickFlag>3
      SetFocus>ExpTitle
      Wait>0.1
      Let>WIN_USEHANDLE=0
      Press Enter
      Label>WaitForFile
      IfFileExists>%temp_dir%BrowserDialog.txt
        ReadLn>%temp_dir%BrowserDialog.txt,1,strFolderName
        GoSub>Populate
        GoSub>MakeBrowserDialog
      Else
        Wait>0.1
        Goto>WaitForFile
      EndIf
    EndIf
  EndIf
  Let>WIN_USEHANDLE=0
  Let>ClickFlag=1
END>Click

SRT>Populate
  SetDialogProperty>Dialog1,MSListBox1,MultiSelect,True
  SetDialogProperty>Dialog1,Edit1,Text,strFolderName
  GetFileList>%strFolderName%\*.*,strFileList,CRLF
  StringReplace>strFileList,%strFolderName%\,,strFileList
  SetDialogProperty>Dialog1,MSListBox1,Text,strFileList
END>Populate

/*
BrowserDialog:
Dialog>Browse%dataCount%
object Browse%dataCount%: TForm Left = 0 Top = 0
object MSButton1: tMSButton end end
EndDialog>Browse%dataCount%
  SetDialogProperty>Browse%dataCount%,MSButton1,InitialDir,%strFolderName%
  SetDialogProperty>Browse%dataCount%,MSButton1,BrowseStyle,fbFolder
  SetDialogProperty>Browse%dataCount%,MSButton1,DoBrowse,True
  GetDialogProperty>Browse%dataCount%,MSButton1,Filename,strFoldName
  WriteLn>%temp_dir%BrowserDialog.txt,wres,strFoldName
//DeleteFile>%temp_dir%BrowserDialog.scp
*/

SRT>MakeBrowserDialog
  IfFileExists>%temp_dir%BrowserDialog.txt
    DeleteFile>%temp_dir%BrowserDialog.txt
  EndIf
  IfFileExists>%temp_dir%BrowserDialog.scp
    DeleteFile>%temp_dir%BrowserDialog.scp
  EndIf
  Add>DataCount,1
  LabelToVar>BrowserDialog,vData%dataCount%
  WriteLn>%temp_dir%BrowserDialog.scp,wres,vData%dataCount%
  Wait>0.1
  ExecuteFile>%temp_dir%BrowserDialog.scp
  Let>BFF_count=0
  Let>ExpTitle=none
  Label>WaitBFF
  LibFunc>user32,SetParent,SPres,ExpTitle,DIALOG1.HANDLE
  Let>WIN_USEHANDLE=1
  GetWindowHandle>Browse For Folder,ExpTitle
  If>ExpTitle<>none
  Else
    Goto>WaitBFF
  EndIf
    LibFunc>user32,SetParent,SPres,ExpTitle,DIALOG1.HANDLE
    Wait>0.1
    MoveWindow>ExpTitle,-10,-77
    ResizeWindow>ExpTitle,240,590
  Let>WIN_USEHANDLE=0
  CloseDialog>Dialog5
END>MakeBrowserDialog

SRT>Process
  GetDialogProperty>Dialog1,MSListBox1,SelectedItems,strFiles
  Let>MSG_WIDTH=600
  Let>MSG_HEIGHT=400
  MDL>Selected Folder:%CRLF%%strFolderName%\%CRLF%%CRLF%Selected Files:%CRLF%%strFiles%
END>Process

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts