Initial Directory on Browse Function

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
boomer
Newbie
Posts: 5
Joined: Tue May 01, 2007 12:16 am

Initial Directory on Browse Function

Post by boomer » Tue Jun 21, 2011 3:28 am

I have a dialog where I am trying to press 1 button to browse and select a root directory. Then when I press the second, third,or forth button it goes to that directory by default opens a file dialog box so I can select a file in that directory. I have been searching to forum for a while and can't seem to get any of the advice posted to work. I am running the latest 12.7 version of MS. I also copied an example of what I am trying to do. Any help would be appreciated.


Dialog>Dialog1
object Dialog1: TForm
Left = 495
Top = 184
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 212
ClientWidth = 431
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 = 17
Top = 19
Width = 75
Height = 25
Caption = 'MSButton1'
DoubleBuffered = True
ParentDoubleBuffered = False
TabOrder = 0
DoBrowse = False
BrowseStyle = fbOpen
end
object MSButton2: tMSButton
Left = 17
Top = 52
Width = 75
Height = 25
Caption = 'MSButton2'
Default = True
DoubleBuffered = True
ParentDoubleBuffered = False
TabOrder = 1
DoBrowse = False
InitialDir = 'c:\Temp'
BrowseStyle = fbOpen
end
object Edit1: TEdit
Left = 102
Top = 22
Width = 315
Height = 21
TabOrder = 2
Text = 'Edit1'
end
object Edit2: TEdit
Left = 103
Top = 55
Width = 314
Height = 21
TabOrder = 3
Text = 'Edit2'
end
end
EndDialog>Dialog1

//AddDialogHandler>Dialog1,btn_GetRootFolder,OnClick,DoBrowseRootFolder
AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowseRootFolder
AddDialogHandler>Dialog1,MSButton2,OnClick,DoBrowseGetFileName

Show>Dialog1,R
//Default Directory
Let>AlwaysInitialDir=c:\temp

SRT>DoBrowseRootFolder
Let>INPUT_BROWSE=2
Input>Rtn_RootFolder,Please select the Root Folder Directory,
SetDialogProperty>Dialog1,Edit1,Text,Rtn_RootFolder
Let>AlwaysInitialDir=Rtn_RootFolder
/*NOW I WANT TO APPLY THIS FOLDER TO the INITIAL FOLDER PATH for future
When I click the browse button on a input box it should take me there
*/
SetDialogProperty>Dialog1,MSButton2,InitialDir,AlwaysInitialDir
END>DoBrowseRootFolder

SRT>DoBrowseGetFileName
Let>Input_Browse=1
Input>Rtn_Filename_WithPath,Select a file Please,
Let>file_path=Rtn_Filename_WithPath
//get the file name on its own
Separate>file_path,\,parts
ArrayCount>parts,MYCOUNT
Let>Rtn_FileName=parts_%MYCOUNT%
SetDialogProperty>Dialog1,Edit2,Text,Rtn_FileName
END>DoBrowseGetFileName

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

Post by JRL » Tue Jun 21, 2011 3:17 pm

This might help get you started. The code I used comes directly from a sample script provided with Macro Scheduler. Dialogs - File Browse Example

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 386
  Top = 201
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  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 = 17
    Top = 19
    Width = 75
    Height = 25
    Caption = 'MSButton1'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 17
    Top = 52
    Width = 75
    Height = 25
    Caption = 'MSButton2'
    Default = True
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Edit1: TEdit
    Left = 102
    Top = 22
    Width = 315
    Height = 21
    TabOrder = 2
  end
  object Edit2: TEdit
    Left = 103
    Top = 55
    Width = 314
    Height = 21
    TabOrder = 3
  end
end
EndDialog>Dialog1
//AddDialogHandler>Dialog1,btn_GetRootFolder,OnClick,DoBrowseRootFolder
AddDialogHandler>Dialog1,MSButton1,OnClick,DoBrowseRootFolder
AddDialogHandler>Dialog1,MSButton2,OnClick,DoBrowseGetFileName
Show>Dialog1,R
//Default Directory
Let>AlwaysInitialDir=c:\temp
SRT>DoBrowseRootFolder
  SetDialogProperty>Dialog1,msButton1,BrowseStyle,fbFolder
  SetDialogProperty>Dialog1,msButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strPathname
  SetDialogProperty>Dialog1,Edit1,Text,strPathName
  Let>AlwaysInitialDir=strPathName
  /*NOW I WANT TO APPLY THIS FOLDER TO the INITIAL FOLDER PATH for future
  When I click the browse button on a input box it should take me there
  */
  SetDialogProperty>Dialog1,MSButton2,InitialDir,AlwaysInitialDir
END>DoBrowseRootFolder
SRT>DoBrowseGetFileName
  SetDialogProperty>Dialog1,msButton2,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton2,Filename,strFileName
  SetDialogProperty>Dialog1,Edit2,Text,strFileName
  Let>file_path=strFileName
  //get the file name on its own
  Separate>file_path,\,parts
  ArrayCount>parts,MYCOUNT
  Let>Rtn_FileName=parts_%MYCOUNT%
  SetDialogProperty>Dialog1,Edit2,Text,Rtn_FileName
END>DoBrowseGetFileName

boomer
Newbie
Posts: 5
Joined: Tue May 01, 2007 12:16 am

Post by boomer » Tue Jun 21, 2011 7:59 pm

Thank you. That is exactly what I needed.

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