Browsing for a dir or a file depending on selected option

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
migro
Macro Veteran
Posts: 151
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Browsing for a dir or a file depending on selected option

Post by migro » Fri Jul 17, 2009 2:59 am

Depending on a selection made in a radiogroup i like to browse (with the same button) for a directory or a file.

I searched the forum but didn't found any hint how to pass the neccesary variables to the "FileBrowse=" function.

Also I didn't found a way to pass the initialdir as a variable to this function.

Would be nice if anybody knows a solution.
regards
migro

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

Post by JRL » Fri Jul 17, 2009 4:45 am

Also I didn't found a way to pass the initialdir as a variable to this function.
If you mean that you can't get filebrowse initialdir to work when the "dir" option is selected. That's been an issue for a while. I first noticed it a year ago, then forgot about it.

Depending on a selection made in a radiogroup i like to browse (with the same button) for a directory or a file.
I don't think there is a way to cause the filebrowse definition to change mid-script. What you could easily do is create two separate filebrowse buttons and put them in the same location in the dialog. Then use the radio button selection to turn one off and the other on using the SetDialogObjectVisible> function.

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=459
   Height=250
   Top=CENTER
   Left=CENTER
   Button=Directory,358,31,75,25,0
   Button=File,358,31,75,25,0
   Edit=msEdit1,14,34,331,
   RadioGroup=msRadioGroup1,Browse Type,352,69,81,44,Directory%CRLF%File,0
   Button=OK,172,174,75,25,3
   FileBrowse=Directory,msEdit1,All Files|*.*,dir
   FileBrowse=File,msEdit1,All Files|*.*,open
EndDialog>Dialog1

Show>dialog1

Label>Loop
GetDialogAction>Dialog1,res1
If>res1=2
  Exit>0
EndIf
If>DIALOG1.MSRADIOGROUP1.ITEMINDEX=0
  SetDialogObjectVisible>Dialog1,msButton1,1
  SetDialogObjectVisible>Dialog1,msButton2,0
Else
  SetDialogObjectVisible>Dialog1,msButton1,0
  SetDialogObjectVisible>Dialog1,msButton2,1
EndIf
Wait>0.01
Goto>Loop

User avatar
migro
Macro Veteran
Posts: 151
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Post by migro » Fri Jul 17, 2009 11:29 am

Dear JRL,

its a great idea. I try it out later on in the evening when I'm back home.
regards
migro

User avatar
migro
Macro Veteran
Posts: 151
Joined: Thu Nov 06, 2003 5:23 pm
Location: Germany
Contact:

Post by migro » Sat Jul 18, 2009 9:42 pm

Thanks JRL,

it works well when I do it like this:

Code: Select all

   FileBrowse=%str111%,strDBFilePath1,DIR|*.mdf,dir
   FileBrowse=%str110%,strDBFilePath1,mdf|*.mdf,open,C:\
Otherwise I can not use the FileBrowse-open to get only *.mdf files.
regards
migro

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