
Sample Code to use File Open dialog box
Thanks for your code examples! See typing error correction below:
(that statement is silently skipped with the effect that the filter
is not set)
on error resume next
set WSHShell = wscript.CreateObject("wscript.Shell")
set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
objDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
^^^
objDlg.FilterIndex = 2
objDlg.MaxFileSize = 260
objDlg.CancelError = true
objDlg.ShowOpen
strFName = objDlg.Filename
WSHShell.popup strFName
Why not translating the code to JScript? It would be nice practice for
VB programmers to write code with the proper case (upper/lower) in variable names,
so the translation process to JS would be much more straight forward.
var WSHShell = WScript.CreateObject("wscript.Shell");
var objDlg = WScript.CreateObject("MSComDlg.CommonDialog");
objDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs|JScript Files (*.js)|*.js";
objDlg.FilterIndex = 3; // we are most interested in *.js files ;-)
objDlg.MaxFileSize = 260;
objDlg.CancelError = false; // no error handler in JScript !!!
objDlg.ShowOpen();
var strFName = objDlg.Filename;
WSHShell.popup(strFName);
Greetings
Herbert
Quote:
> on error resume next
> set WSHShell = wscript.CreateObject("wscript.Shell")
> set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
> comDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
> objDlg.FilterIndex = 2
> objDlg.MaxFileSize = 260
> objDlg.CancelError = true
> objDlg.ShowOpen
> strFName = objDlg.Filename
> WSHShell.popup strFName
> Regards,
> Ian Morrish
> http://wsh.glazier.co.nz WSH FAQ
> http://ils.glazier.co.nz (NetMeeting)
> http://www.glazier.co.nz
--
+----------------------------+------------------------------+
| Herbert Hotz | Voice: +41 1 381 2122 |
| APS Applied Systematics AG | Fax: +41 1 381 2127 |
| Muehle Tiefenbrunnen | GSM-SMS: +41 79 402 5704 |
| Seefeldstrasse 231 | URL: http://www.aps.ch/ |
+----------------------------+------------------------------+