前回
![左矢印](https://stat.ameba.jp/blog/ucs/img/char/char2/285.gif)
![左矢印](https://stat.ameba.jp/blog/ucs/img/char/char2/285.gif)
![あはは。。。](https://emoji.ameba.jp/img/user/sa/samantha-kaicho/324806.gif)
![あせる](https://stat.ameba.jp/blog/ucs/img/char/char2/029.gif)
・・・んで、
MS-Docとか、ググったりとか、してみてたら、JScript.NET ていうのを初めて知りました。←いまごろ!!!!
インタプリタ JScript.WHS から直に.NET Frameworkクラスのオブジェクトをイジることはできないらしい?!(・・のかな?
![シラー](https://stat.ameba.jp/blog/ucs/img/char/char2/145.gif)
![あせ](https://emoji.ameba.jp/img/user/na/nan-non/2221556.gif)
まぁ、とりま、ソースを↓。
//JScript.NETでつくるOpenFileDialogクラスではどのプロパティを使えるのか?
//https://bit.ly/2XGHYul(MS.Doc)。
var DEBUG=true;
import System; //念のため。(^_^;ゞ汗;
import System.Windows.Forms; //ダイアログBOXポップアップが"入ってる"。
//OpenFileDialogのインスタンスを生成してプロパティへのアクセスを試してみる。
class OpnFileDlg {
var Dlg: OpenFileDialog; //OpenFileDialogクラスのインスタンス。
//ココ↓にドキュメントされてるプロパティを全部試してみます。
//https://bit.ly/3lNwoWC(OpenFileDialogクラス)。
var bAddExtension: Boolean;
var bAutoUpgradeEnabled: Boolean;
var bCanRaiseEvents: Boolean;
var bCheckFileExists: Boolean;
var bCheckPathExists: Boolean;
var sClientGuid: String; //とりまString型で。
var oContainer: Object; //とりまObject型で(^_^ゞ汗;。
var oCustomPlaces: Object; //上に同じ。
var sDefaultExt: String;
var bDereferenceLinks: Boolean;
var bDesignMode: Boolean;
var aEvents: Array; //とりまArrayということで(^_^;ゞ汗
var sFileName: String;
var aFileNames: Array;
var sFilter: String;
var nFilterIndex: Number; //ほんまはUINTかな?!。
var sInitialDirectory: String;
var nInstance: Number; //ポインタなんやけど、ね・・(^_^;ゞ汗。
var bMultiselect: Boolean;
var nOptions: Number; //Int32。でも、アカンかも?!汗;
var bReadOnlyChecked: Boolean;
var bRestoreDirectory: Boolean;
var sSafeFileName: String;
var aSafeFileNames: Array;
var bShowHelp: Boolean;
var bShowReadOnly: Boolean;
var oSite: Object; //これ、アカンかも?!。
var bSupportMultiDottedExtensions: Boolean;
var oTag: Object;
var sTitle: String;
var bValidateNames: Boolean;
//コンストラクタ。・・・って、ただプロパティ並べただけのクラスですけど、。。。
function OpnFileDlg(){
this.Dlg=new OpenFileDialog(); //これがちょうど50行目。
//
this.bAddExtension =this.Dlg.AddExtension;
this.bAutoUpgradeEnabled =this.Dlg.AutoUpgradeEnabled;
this.bCanRaiseEvents =this.Dlg.CanRaiseEvents;
this.bCheckFileExists =this.Dlg.CheckFileExists;
this.bCheckPathExists =this.Dlg.CheckPathExists;
this.sClientGuid =this.Dlg.ClientGuid;
this.oContainer =this.Dlg.Container;
this.oCustomPlaces =this.Dlg.CustomPlaces;
this.sDefaultExt =this.Dlg.DefaultExt;
this.bDereferenceLinks =this.Dlg.DereferenceLinks;
this.bDesignMode =this.Dlg.DesignMode;
this.aEvents =this.Dlg.Events;
this.sFileName =this.Dlg.FileName;
this.aFileNames =this.Dlg.FileNames;
this.sFilter =this.Dlg.Filter;
this.nFilterIndex =this.Dlg.FilterIndex;
this.sInitialDirectory =this.Dlg.InitialDirectory;
this.nInstance =this.Dlg.Instance;
this.bMultiselect =this.Dlg.Multiselect;
this.nOptions =this.Dlg.Options;
this.bReadOnlyChecked =this.Dlg.ReadOnlyChecked;
this.bRestoreDirectory =this.Dlg.RestoreDirectory;
this.sSafeFileName =this.Dlg.SafeFileName;
this.aSafeFileNames =this.Dlg.SafeFileNames;
this.bShowHelp =this.Dlg.ShowHelp;
this.bShowReadOnly =this.Dlg.ShowReadOnly;
this.oSite =this.Dlg.Site;
this.bSupportMultiDottedExtensions= this.Dlg.SupportMultiDottedExtensions;
this.oTag =this.Dlg.Tag;
this.sTitle =this.Dlg.Title;
this.bValidateNames =this.Dlg.ValidateNames;
};
}
//ただ、newするだけ。
var oDlg=new OpnFileDlg();
//後始末。
oDlg.Dlg.Dispose();
oDlg.Dlg=null;
oDlg=null;
//https://bit.ly/2XGHYul(MS.Doc)。
var DEBUG=true;
import System; //念のため。(^_^;ゞ汗;
import System.Windows.Forms; //ダイアログBOXポップアップが"入ってる"。
//OpenFileDialogのインスタンスを生成してプロパティへのアクセスを試してみる。
class OpnFileDlg {
var Dlg: OpenFileDialog; //OpenFileDialogクラスのインスタンス。
//ココ↓にドキュメントされてるプロパティを全部試してみます。
//https://bit.ly/3lNwoWC(OpenFileDialogクラス)。
var bAddExtension: Boolean;
var bAutoUpgradeEnabled: Boolean;
var bCanRaiseEvents: Boolean;
var bCheckFileExists: Boolean;
var bCheckPathExists: Boolean;
var sClientGuid: String; //とりまString型で。
var oContainer: Object; //とりまObject型で(^_^ゞ汗;。
var oCustomPlaces: Object; //上に同じ。
var sDefaultExt: String;
var bDereferenceLinks: Boolean;
var bDesignMode: Boolean;
var aEvents: Array; //とりまArrayということで(^_^;ゞ汗
var sFileName: String;
var aFileNames: Array;
var sFilter: String;
var nFilterIndex: Number; //ほんまはUINTかな?!。
var sInitialDirectory: String;
var nInstance: Number; //ポインタなんやけど、ね・・(^_^;ゞ汗。
var bMultiselect: Boolean;
var nOptions: Number; //Int32。でも、アカンかも?!汗;
var bReadOnlyChecked: Boolean;
var bRestoreDirectory: Boolean;
var sSafeFileName: String;
var aSafeFileNames: Array;
var bShowHelp: Boolean;
var bShowReadOnly: Boolean;
var oSite: Object; //これ、アカンかも?!。
var bSupportMultiDottedExtensions: Boolean;
var oTag: Object;
var sTitle: String;
var bValidateNames: Boolean;
//コンストラクタ。・・・って、ただプロパティ並べただけのクラスですけど、。。。
function OpnFileDlg(){
this.Dlg=new OpenFileDialog(); //これがちょうど50行目。
//
this.bAddExtension =this.Dlg.AddExtension;
this.bAutoUpgradeEnabled =this.Dlg.AutoUpgradeEnabled;
this.bCanRaiseEvents =this.Dlg.CanRaiseEvents;
this.bCheckFileExists =this.Dlg.CheckFileExists;
this.bCheckPathExists =this.Dlg.CheckPathExists;
this.sClientGuid =this.Dlg.ClientGuid;
this.oContainer =this.Dlg.Container;
this.oCustomPlaces =this.Dlg.CustomPlaces;
this.sDefaultExt =this.Dlg.DefaultExt;
this.bDereferenceLinks =this.Dlg.DereferenceLinks;
this.bDesignMode =this.Dlg.DesignMode;
this.aEvents =this.Dlg.Events;
this.sFileName =this.Dlg.FileName;
this.aFileNames =this.Dlg.FileNames;
this.sFilter =this.Dlg.Filter;
this.nFilterIndex =this.Dlg.FilterIndex;
this.sInitialDirectory =this.Dlg.InitialDirectory;
this.nInstance =this.Dlg.Instance;
this.bMultiselect =this.Dlg.Multiselect;
this.nOptions =this.Dlg.Options;
this.bReadOnlyChecked =this.Dlg.ReadOnlyChecked;
this.bRestoreDirectory =this.Dlg.RestoreDirectory;
this.sSafeFileName =this.Dlg.SafeFileName;
this.aSafeFileNames =this.Dlg.SafeFileNames;
this.bShowHelp =this.Dlg.ShowHelp;
this.bShowReadOnly =this.Dlg.ShowReadOnly;
this.oSite =this.Dlg.Site;
this.bSupportMultiDottedExtensions= this.Dlg.SupportMultiDottedExtensions;
this.oTag =this.Dlg.Tag;
this.sTitle =this.Dlg.Title;
this.bValidateNames =this.Dlg.ValidateNames;
};
}
//ただ、newするだけ。
var oDlg=new OpnFileDlg();
//後始末。
oDlg.Dlg.Dispose();
oDlg.Dlg=null;
oDlg=null;
![1](https://stat.ameba.jp/blog/ucs/img/char/char2/269.gif)
![ブログ](https://emoji.ameba.jp/img/user/fl/flesher/430222.gif)
![2](https://stat.ameba.jp/blog/ucs/img/char/char2/270.gif)
※〔作成例〕↓「メモ帳」開いてコピペ貼り付け、JSC.CMD という名前を付けて保存して、C:\WINDOWSフォルダに入れときます。その後、コマンドプロンプトを開いて、「jsc /?」とタイプしEnterすると、JScriptコンパイラのヘルプが表示されたら、OK。
@echo off
set JSC1=%SystemRoot%\Microsoft.NET\Framework\v1.1.4322\jsc.exe
set JSC2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\jsc.exe
set JSC4=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\jsc.exe
set JSC=
IF EXIST %JSC1% set JSC=%JSC1%
IF EXIST %JSC2% set JSC=%JSC2%
IF EXIST %JSC4% set JSC=%JSC4%
IF NOT (%JSC%) == () goto EXECJSC
echo JScript.NETコンパイラはありませんでした。
goto ENDEXIT
:EXECJSC
%JSC% %1 %2 %3 %4 %5 %6 %7 %8 %9
:ENDEXIT
set JSC1=%SystemRoot%\Microsoft.NET\Framework\v1.1.4322\jsc.exe
set JSC2=%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\jsc.exe
set JSC4=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\jsc.exe
set JSC=
IF EXIST %JSC1% set JSC=%JSC1%
IF EXIST %JSC2% set JSC=%JSC2%
IF EXIST %JSC4% set JSC=%JSC4%
IF NOT (%JSC%) == () goto EXECJSC
echo JScript.NETコンパイラはありませんでした。
goto ENDEXIT
:EXECJSC
%JSC% %1 %2 %3 %4 %5 %6 %7 %8 %9
:ENDEXIT
![JscHelp_コマンドプロンプト](https://stat.ameba.jp/user_images/20210923/02/2katteniyucch1/88/48/j/o0576041415005093607.jpg?caw=800)
![3](https://stat.ameba.jp/blog/ucs/img/char/char2/271.gif)
![1](https://stat.ameba.jp/blog/ucs/img/char/char2/269.gif)
> jsc /t:winexe /autoref 〔保存したファイル名〕
とやると、コンパイル・エラー・メッセージが表示されます(←
![えっ](https://stat.ameba.jp/blog/ucs/img/char/char2/147.gif)
![4](https://stat.ameba.jp/blog/ucs/img/char/char2/272.gif)
![あせ](https://emoji.ameba.jp/img/user/yu/yu-yu-yu-go1008/3281977.gif)
--ワタシのウインドウズXP(バージョン8のコンパイラが作動しました)でやってみたら、以下↓のようなエラーメッセージでした。
![ひらめき電球](https://stat.ameba.jp/blog/ucs/img/char/char2/089.gif)
Microsoft(R) JScript Compiler version 8.00.50727
for Microsoft(R) .NET Framework version 2.0.50727
Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.
JscrpFDlg.jse(54,27) : error JS1123: 'this.Dlg.CanRaiseEvents' にこのスコープからアクセスできません。
JscrpFDlg.jse(57,33) : error JS1151: 'System.Windows.Forms.OpenFileDialog' 型のオブジェクトにそのようなメンバは含まれていません。
JscrpFDlg.jse(62,24) : error JS1123: 'this.Dlg.DesignMode' にこのスコープからアクセスできません。
JscrpFDlg.jse(63,20) : error JS1123: 'this.Dlg.Events' にこのスコープからアクセスできません。
JscrpFDlg.jse(69,22) : error JS1123: 'this.Dlg.Instance' にこのスコープからアクセスできません。
JscrpFDlg.jse(71,21) : error JS1123: 'this.Dlg.Options' にこのスコープからアクセスできません。
for Microsoft(R) .NET Framework version 2.0.50727
Copyright (C) Microsoft Corporation 1996-2005. All rights reserved.
JscrpFDlg.jse(54,27) : error JS1123: 'this.Dlg.CanRaiseEvents' にこのスコープからアクセスできません。
JscrpFDlg.jse(57,33) : error JS1151: 'System.Windows.Forms.OpenFileDialog' 型のオブジェクトにそのようなメンバは含まれていません。
JscrpFDlg.jse(62,24) : error JS1123: 'this.Dlg.DesignMode' にこのスコープからアクセスできません。
JscrpFDlg.jse(63,20) : error JS1123: 'this.Dlg.Events' にこのスコープからアクセスできません。
JscrpFDlg.jse(69,22) : error JS1123: 'this.Dlg.Instance' にこのスコープからアクセスできません。
JscrpFDlg.jse(71,21) : error JS1123: 'this.Dlg.Options' にこのスコープからアクセスできません。
ちなみに、・・・
古いコンパイラ(バージョン7の。v1.1.4322フォルダに入ってるヤツ)だと、もっとエラーが多くなります。
![あはは。。。](https://emoji.ameba.jp/img/user/sa/samantha-kaicho/324806.gif)
![5](https://stat.ameba.jp/blog/ucs/img/char/char2/273.gif)
CanRaiseEvents
ClientGuid
DesignMode
Events
Instance
Option
・・・の各プロパティが使えません。 --- ってことでしょうか?!
![あせあせ](https://emoji.ameba.jp/img/user/mo/moito/285494.gif)
![汗](https://stat.ameba.jp/blog/ucs/img/char/char2/028.gif)
※エラーメッセージは出てませんけど、たぶん Site プロパティもダメです。
![!?](https://stat.ameba.jp/blog/ucs/img/char/char2/177.gif)
触るとヤケド!=「実行時エラー」になるみたい。。。
![ガーン](https://stat.ameba.jp/blog/ucs/img/char/char2/141.gif)
★★★これだけじゃぁ、ちと、おもしろくないので、...蛇足ですが。
ソースコードのエラー行(上↑の例では、54,57,62,63,69,71行)をコメントにして(行頭に //)、
「後始末」の前に、下記↓のコードを追加
![メモ](https://stat.ameba.jp/blog/ucs/img/char/char2/131.gif)
ファイル選択ポップアップダイアログができますよ。
![ニコニコ](https://stat.ameba.jp/blog/ucs/img/char/char2/139.gif)
![ハート](https://emoji.ameba.jp/img/user/ca/caffe-macchiato/28736.gif)
![音譜](https://stat.ameba.jp/blog/ucs/img/char/char2/038.gif)
〔※追加するコード↓〕 newした後の、「後始末」の前に3行(コメント行除けば2行)を挿入。
oDlg.Dlg.ShowDialog(); //ファイル選択ダイアログ表示。
//選択したファイル名を表示(・・おまけです。
WshShellでポップアップ表示)。
(new ActiveXObject("WScript.Shell")).Popup(oDlg.Dlg.FileName);
//選択したファイル名を表示(・・おまけです。
![ニコニコ](https://stat.ameba.jp/blog/ucs/img/char/char2/139.gif)
(new ActiveXObject("WScript.Shell")).Popup(oDlg.Dlg.FileName);