Dialog, FileBrowse

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
durexlw
Newbie
Posts: 18
Joined: Mon Mar 17, 2008 1:19 pm

Dialog, FileBrowse

Post by durexlw » Tue Apr 01, 2008 5:55 pm

In it's simplified form, I have a Dialog, showing two textfields and two buttons, let's say:
msEdit1 button1
msEdit2 button2

With FileBrowse: msEdit1 is linked to button1 and msEdit2 is linked to button2

I would like:
When button1 is clicked and the user selects a file, I want to suggest a default path in msEdit2. Off course, I still want msEdit2 to be linked to button2 with FileBrowse, in case the file isn't at the default location.

In other words: if the user clicks button1, an openfile-dialog is shown and when the user selects his file, msEdit1 shows the path to the file the user selected.
As soon as msEdit1 contains a path, I want to put in a default path in msEdit2, based on the content of msEdit1. Since button2 is linked to msEdit2 the user can still change the path if the next file is not at the default location.

Can this be done? How?

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

Post by JRL » Tue Apr 01, 2008 6:12 pm

Something like this?

If msedit1 is c:\ msedit2 will be C:\Program Files but users can still make another selection because dirFlag variable must be set to 0 to make msedit2 change to C:\Program Files and it is only set to 0 at the start. It gets set to 1 if msedit1 is c:\

Hope this makes sense.

Code: Select all

Let>PreSelectedPath=C:\
Let>dirFlag=0

Dialog>Dialog1
   Caption=Dialog1
   Width=333
   Height=217
   Top=181
   Left=49
   Edit=msEdit1,48,32,121,
   Edit=msEdit2,48,64,121,
   Button=Browse1,200,32,75,25,0
   Button=Browse2,200,64,75,25,0
   Button=Ok,112,128,75,25,2
   FileBrowse=Browse1,msEdit1,All Files|*.*,dir
   FileBrowse=Browse2,msEdit2,All Files|*.*,dir
EndDialog>Dialog1

Show>dialog1

Label>Loop
GetDialogAction>dialog1,res1
If>res1=2,EOF
If>{(%dialog1.msedit1%=%PreSelectedPath%)and(%DirFlag%=0)}
  Let>dialog1.msedit2=C:\Program Files
  ResetDialogAction>dialog1
  Let>DirFlag=1
EndIf
Wait>0.01
Goto>Loop

Label>EOF

durexlw
Newbie
Posts: 18
Joined: Mon Mar 17, 2008 1:19 pm

Post by durexlw » Tue Apr 01, 2008 6:30 pm

JRL, makes perfect sense.

Drawing from your inspiration, I made a small adjustment: IfFileExists>%Dialog1.msEdit1%

Like this, msEdit2 only get's updated when a valid file is selected and when people type, msEdit2 doesn't get updated unless a valid path is typed.

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=333
   Height=217
   Top=181
   Left=49
   Edit=msEdit1,48,32,121,
   Edit=msEdit2,48,64,121,
   Button=Browse1,200,32,75,25,0
   Button=Browse2,200,64,75,25,0
   Button=Ok,112,128,75,25,2
   FileBrowse=Browse1,msEdit1,All Files|*.*,dir
   FileBrowse=Browse2,msEdit2,All Files|*.*,dir
EndDialog>Dialog1

Show>dialog1

Label>Loop
GetDialogAction>dialog1,res1
If>res1=2,EOF
If>dialog1.msedit1<IfFileExists>%Dialog1.msEdit1%
	Let>Dialog1.msEdit2=C:\Program Files
	ResetDialogAction>Dialog1
    Endif
EndIf
Wait>0.01
Goto>Loop

Label>EOF

Thanks for the help man. I appreciate it.

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