In the vbs script design, if you can use the system dialog box provided by Windows, you can simplify the ease of use of the script and make the script more user-friendly, which is rarely used. However, vbs does not provide such a function, of course, the method still uses COM objects.
1. safrcfiledlg. filesave object: attributes: Filename-specify the default file name; filetype-
Specify the file extension. openfilesavedlg-display the file storage box method.
2. safrcfiledlg. fileopen object: Filename-default file name attribute; openfileopendlg-Display Method for opening the file box.
3. useraccounts. commondialog object: Filter-extension attributes ("vbs file | *. vbs | all files | *.*");
Filterindex-specified
Initialdir-specify the default folder
Filename-specified file name
Flags-Dialog Box Type
Showopen method:
Very simple. OK. Let's take two simple examples:
Example 1: save an object
Set objdialog = Createobject ("safrcfiledlg. filesave ")
Set objfso = Createobject ("scripting. FileSystemObject ")
Objdialog. filename = "test"
Objdialog. filetype = ". txt"
Intreturn = objdialog. openfilesavedlg
If intreturn then
Objfso. createtextfile (objdialog. filename & objdialog. filetype)
Else
Wscript. Quit
End if
Note: 1. The safrcfiledlg. filesave object only provides a user-friendly interface, and does not save the file itself. You need to use the FSO object to save the file. 2. Use the filetype attribute to specify the default file type. 3. When calling the openfilesavedlg method, it is best to save the returned value to a variable and use it to determine whether the user presses "OK" or "cancel.
Example 2: open a file
Set objfile = Createobject ("safrcfiledlg. fileopen ")
Intret = objfile. openfileopendlg
If intret then
Msgbox "file opened successfully! The file name is: "& objfile. filename
Else
Wscript. Quit
End if
Example 3: complex file opening dialog box
Set objdialog = Createobject ("useraccounts. commondialog ")
Objdialog. Filter = "vbs file | *. vbs"
Objdialog. initialdir = "C :/"
Tfile = objdialog. showopen
If tfile then
Strloadfile = objdialog. filename
Msgbox strloadfile
Else
Wscript. Quit
End if
Note: Add objdialog. Flags = & h020 to the script to see what will happen.