FileBrowse and Save
Moderators: JRL, Dorian (MJT support)
FileBrowse and Save
Is it possible to save a file through a dialog using the FileBrowse and save?
I have created a very simple dialog to test this and have been able to get the "Save As" window to open but the file does not save. What am I missing?
Here is the script:
Dialog>Dialog1
Caption=Dialog1
Width=166
Height=135
Top=CENTER
Left=CENTER
Edit=msEdit1,16,16,121,
Button=Save As,40,56,75,25,4
FileBrowse=Save As,msEdit1,Text Documents (*.txt)|*.txt|All Files|*.*,save,C:\,test.txt
EndDialog>Dialog1
Show>Dialog1,r
I have created a very simple dialog to test this and have been able to get the "Save As" window to open but the file does not save. What am I missing?
Here is the script:
Dialog>Dialog1
Caption=Dialog1
Width=166
Height=135
Top=CENTER
Left=CENTER
Edit=msEdit1,16,16,121,
Button=Save As,40,56,75,25,4
FileBrowse=Save As,msEdit1,Text Documents (*.txt)|*.txt|All Files|*.*,save,C:\,test.txt
EndDialog>Dialog1
Show>Dialog1,r
Hello Rory,
The purpose of the dialog command is to display dialog boxes but it won't really do active things. So your program is calling a dialog box named "Save As" but is not actually saving the file. You need to catch the name of the file in MsEdit1 (just to make sure the user hasn't changed it while in the Save As window). Then you'll have to use the CopyFile> command to do the job.
Good Luck
The purpose of the dialog command is to display dialog boxes but it won't really do active things. So your program is calling a dialog box named "Save As" but is not actually saving the file. You need to catch the name of the file in MsEdit1 (just to make sure the user hasn't changed it while in the Save As window). Then you'll have to use the CopyFile> command to do the job.
Good Luck

- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
A dialog is an interface for a user to use. The user clicks the button which opens the Save As dialog. The user then chooses a location and clicks ok. All the save as dialog does is return the user's choice (the path and chosen file name) to the script. It's up to the programmer what then to do with it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Thanks for the replies.
I have another question now.
If I try to set the Default file name to a variable of the msEdit, the file name does not carry over into the "Save As" window.
If I hard code a file name in at the end of the FileBrowse line that file name is carried over the the "Save As" window.
Why doesnt the variable work?
Dialog>Dialog1
Caption=Dialog1
Width=166
Height=135
Top=CENTER
Left=CENTER
Edit=msEdit1,16,16,121,
Button=Save As,40,56,75,25,4
FileBrowse=Save As,msEdit1,Text Documents (*.txt)|*.txt|All Files|*.*,save,C:\,%Dialog1.msEdit1%
EndDialog>Dialog1
Show>Dialog1,r
MessageModal>%Dialog1.msEdit1%
I have another question now.
If I try to set the Default file name to a variable of the msEdit, the file name does not carry over into the "Save As" window.
If I hard code a file name in at the end of the FileBrowse line that file name is carried over the the "Save As" window.
Why doesnt the variable work?
Dialog>Dialog1
Caption=Dialog1
Width=166
Height=135
Top=CENTER
Left=CENTER
Edit=msEdit1,16,16,121,
Button=Save As,40,56,75,25,4
FileBrowse=Save As,msEdit1,Text Documents (*.txt)|*.txt|All Files|*.*,save,C:\,%Dialog1.msEdit1%
EndDialog>Dialog1
Show>Dialog1,r
MessageModal>%Dialog1.msEdit1%
From help text for "FileBrowse" under "Dialog", what would appear to be the obvious solution to this issue:
As Rory has found, hardcoding the directory and filename at the end of the FileBrowse line will put the requested information into the Save As window. But I agree with him that there does not seem to be any way to use a variable to cause the Save As window to use a specific directory requesting a specific file.
An obvious workaround would be to dynamically create a script containing the dialog then call that script using the macro command. But it sure seems like the instuction for FileBrowse is telling us that this shouldn't be necessary.
Later,
Dick
Edit-1
Thought I'd show one iteration of Rory's script as I've modified it attempting to make this work.
I've tried multiple ways to make this work but I have not been successful.initialdir and filename allow the browse box to default to a directory and/or filename. To set initialdir and/or filename at run time set dialogName.TextObjectName.fbinit=initialdir,filename
As Rory has found, hardcoding the directory and filename at the end of the FileBrowse line will put the requested information into the Save As window. But I agree with him that there does not seem to be any way to use a variable to cause the Save As window to use a specific directory requesting a specific file.
An obvious workaround would be to dynamically create a script containing the dialog then call that script using the macro command. But it sure seems like the instuction for FileBrowse is telling us that this shouldn't be necessary.
Later,
Dick
Edit-1
Thought I'd show one iteration of Rory's script as I've modified it attempting to make this work.
Code: Select all
Let>Dialog1.msEdit1.fbinit=C:\,newfilename.txt
Dialog>Dialog1
Caption=File Name
Width=166
Height=135
Top=CENTER
Left=CENTER
Edit=msEdit1,16,16,121,
Button=Save As,96,72,59,25,4
Button=Ok,8,72,57,25,3
Default=Ok
FileBrowse=Save As,msEdit1,Text Documents (*.txt)|*.txt|All Files|*.*,save,,
EndDialog>Dialog1
Show>Dialog1
Label>start
Wait>0.01
GDA>dialog1,r1
If>r1=2,finish
If>r1=3,process
If>r1=4,process
Goto>start
SRT>process
MessageModal>%Dialog1.msEdit1%
//Do stuff
ResetDialogAction>dialog1
END>process
Label>finish
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You're all confusing me. What are you trying to do?
You want to set the filename of the filebrowse at run time? Do this:
Let>Dialog1.msEdit1.fbinit=C:\,newfilename.txt
ResetDialogAction>dialog1
Just like you would set the value of any other dialog object.
You want to set the filename of the filebrowse at run time? Do this:
Let>Dialog1.msEdit1.fbinit=C:\,newfilename.txt
ResetDialogAction>dialog1
Just like you would set the value of any other dialog object.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
What I would like to do it to place a file name into an edit box in the dialog as a variable. This would only be a file name without the address. That way a person can click on the Save As button and have the file name placed into the file name box on the Save As window. I know a person can type the file name in on the Save As window, but with the Dialog that I am creating, it would be nice to have everything infront of the user before clicking the Save As button.
Is everyone confused now?
Rory
Is everyone confused now?
Rory
I'm most dangerous when I think I get it
from Marcus' last explanation, try this.

from Marcus' last explanation, try this.
Code: Select all
Let>filename=newfilename.txt
Let>directory=c:\
Let>Dialog1.msEdit1=%directory%%filename%
Dialog>Dialog1
Caption=Save As
Width=166
Height=135
Top=CENTER
Left=CENTER
Edit=msEdit1,16,16,121,
Button=Save As,96,72,59,25,4
Button=Ok,8,72,57,25,3
Default=Ok
fbinit=C:\,newfilename.txt
FileBrowse=Save As,msEdit1,Text Documents (*.txt)|*.txt|All Files|*.*,save,,
EndDialog>Dialog1
Show>Dialog1
Let>Dialog1.msEdit1.fbinit=%directory%,%filename%
ResetDialogAction>dialog1
Closedialog>dialog1
Show>Dialog1
Label>start
Wait>0.01
GDA>dialog1,r1
If>r1=2,finish
If>r1=3,process
If>r1=4,process
Goto>start
SRT>process
MessageModal>%Dialog1.msEdit1%
//Do stuff
ResetDialogAction>dialog1
END>process
Label>finish
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
1. Erm, why show and close the dialog again? What's wrong with:
2. But, since this example sets it on startup why not just do:
Am I missing the problem here? 
Code: Select all
Show>Dialog1
GetDialogAction>Dialog1,r
Let>Dialog1.msEdit1.fbinit=c:\,newfilename.txt
ResetDialogAction>Dialog1
Code: Select all
Dialog>Dialog1
Caption=Save As
Width=166
Height=135
Top=CENTER
Left=CENTER
Edit=msEdit1,16,16,121,
Button=Save As,96,72,59,25,4
Button=Ok,8,72,57,25,3
Default=Ok
FileBrowse=Save As,msEdit1,Text Documents (*.txt)|*.txt|All Files|*.*,save,c:\,newfilename.txt
EndDialog>Dialog1
Show>Dialog1
Label>start
Wait>0.01
GDA>dialog1,r1
If>r1=2,finish
If>r1=3,process
If>r1=4,process
Goto>start
SRT>process
MessageModal>%Dialog1.msEdit1%
//Do stuff
ResetDialogAction>dialog1
END>process
Label>finish

Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
I believe that its the other way around. The filebrowse requires msedit to have someplace to store the selection. If you check the value of "dialog1.msedit1" you'll find it contains the selected file name.What is the reason for associating the FileBrowse with msEdit when msEdit does not carry over into the Save As window?
This might be dangerous because it might be exploiting a flaw but I discovered some time ago that you can define an invisible edit box in a dialog like this:
Edit=msEdit1,
Note the comma at the end is needed.
The purpose this could serve would be to help remove dialog user confusion. As Rory stated, what good is the edit box if the user is going to browse for a filename and the edit box contents won't carry over into the browse window? The edit box is necessary because it captures the file selection and passes it on to a variable that can be used later in the script. But nobody really needs to see it.
The following script is a revision of the above script and demonstrates how an invisible edit box might be used: I removed the extraneous code pointed out by Marcus. I also added code to rewrite the value of Dialog1.msEdit1.fbinit so that each time a new directory\file is selected it is remembered the next time browse is selected.
Edit=msEdit1,
Note the comma at the end is needed.
The purpose this could serve would be to help remove dialog user confusion. As Rory stated, what good is the edit box if the user is going to browse for a filename and the edit box contents won't carry over into the browse window? The edit box is necessary because it captures the file selection and passes it on to a variable that can be used later in the script. But nobody really needs to see it.
The following script is a revision of the above script and demonstrates how an invisible edit box might be used: I removed the extraneous code pointed out by Marcus. I also added code to rewrite the value of Dialog1.msEdit1.fbinit so that each time a new directory\file is selected it is remembered the next time browse is selected.
Code: Select all
Let>filename=newfilename.txt
Let>directory=c:\
Dialog>Dialog1
Caption=Select File
Width=166
Height=94
Top=CENTER
Left=CENTER
Edit=msEdit1,
Button=Browse,88,24,59,25,4
Button=Ok,8,24,59,25,3
FileBrowse=Browse,msEdit1,Text Documents (*.txt)|*.txt|All Files|*.*,save,,
EndDialog>Dialog1
Show>Dialog1
Let>Dialog1.msEdit1.fbinit=%directory%,%filename%
ResetDialogAction>dialog1
Label>start
Wait>0.01
GDA>dialog1,r1
If>r1=2,finish
If>r1=3,process
Goto>start
SRT>process
If>%Dialog1.msEdit1%=
Let>Dialog1.msEdit1=No File Selected
EndIf
MessageModal>%Dialog1.msEdit1%
If>%Dialog1.msEdit1%=No File Selected
//do nothing
Else
Separate>%Dialog1.msEdit1%,\,var
Let>filename=var_%var_count%
sub>var_count,1
Let>counter=0
Let>directory=
Repeat>counter
add>counter,1
Let>value=var_%counter%
concat>directory,%value%\
Until>counter=var_count
Let>Dialog1.msEdit1.fbinit=%directory%,%filename%
EndIf
ResetDialogAction>dialog1
//Do stuff
END>process
Label>finish