JScriptで普通に a / b のように割り算をやるとaもbもdoubleに変換して 計算してしまうので、そうならないようにするには、下のように するしかないのかな。 「独自に作成したコードから直接使用するためのものではありません」な メソッド使ってるけど。
import Microsoft.VisualBasic.CompilerServices; import System; var a : int = 123; var b : int = 45; var x : int; x = Operators.IntDivideObject(a, b); Console.WriteLine(x);
と思ったけどOperators.IntDivideObjectを一々呼ぶよりは単純に x = int(a / b); としたほうがはるかに速かった。
JScript.NETで var name = ["line1", "line2", "line3"].join("\n"); と var name = "line1\n" + "line2\n" + "line3\n"; の処理速度を比べてみたら後者の方がはるかに速かった。 後者はコンパイル時に var name = "line1\nline2\nline3\n"; とみなしているようです。
ダイアログの表示だけなら // monadialog.js import Accessibility; import System.Drawing; import System.Windows.Forms; var f: Form = new Form(); f.Size = new System.Drawing.Size(300, 125); f.Text = "確認"; var mona : Label = new Label(); mona.AutoSize = true; mona.BackColor = Color.White; mona.BorderStyle = BorderStyle.FixedSingle; mona.Font = new Font("MS PGothic", 12); mona.Location = new Point(10, 10); mona.Text = "\n ∧_∧ \n( ´∀`) \n( )"; f.Controls.Add(mona); var message : Label = new Label(); message.Text = "ダイアログを表示してみますた。"; message.AutoSize = true; message.Location = new Point(100, 20); f.Controls.Add(message); var yes: Button = new Button(); yes.DialogResult = DialogResult.Yes; yes.Location = new Point(110, 60); yes.NotifyDefault(true); yes.Text = "はい"; f.Controls.Add(yes); var no : Button = new Button(); no.DialogResult = DialogResult.No; no.Location = new Point(190, 60); no.Text = "いいえ"; f.Controls.Add(no); f.ShowDialog();
91 名前:デフォルトの名無しさん [2006/09/30(土) 21:53:54 ]
WSH(JScript)からJScript.NETで作ったコンポーネントを利用するテスト
D:\>type MyServer.js import System; import System.Runtime.InteropServices; public Guid("E65CFE0B-2F1E-45A4-9FBE-4CC1D2B20AE8") ProgId("MyServer.Sample") class MyServerSample { private var _property : int = 0; public function Method(s: String): int { Console.WriteLine(s); return s.Length; } public function get Property() : int { return _property; } public function set Property(n : int) { _property = n; } }
D:\>type test.js var Sample = new ActiveXObject("MyServer.Sample"); Sample.Property = 123; Sample.Method(Sample.Property);
D:\>cscript //nologo test.js 123
D:\>
93 名前:デフォルトの名無しさん [2006/10/06(金) 16:48:28 ]
msdn2.microsoft.com/ja-jp/library/system.timers.timer.aspx の使用例を JScriptにしてみたけど、とりあえず動作するからこんなんでいいのかな。 import System; import System.Timers; public class Timer1 { public static function Main(): void { var aTimer : Timer = new Timer(); aTimer.add_Elapsed(OnTimedEvent); aTimer.Interval = 2000; aTimer.Enabled = true; Console.WriteLine("Press the Enter key to exit the program."); Console.ReadLine(); GC.KeepAlive(aTimer); } private static function OnTimedEvent(source : Object, e : ElapsedEventArgs): void { Console.WriteLine("Hello World!"); } } Timer1.Main();
J:\>type SampleControl.js import Accessibility; import System; import System.ComponentModel; import System.Drawing; import System.Runtime.InteropServices; import System.Windows.Forms; public Guid("5C466CE7-5C06-49FA-869D-E0BBE71F833B") ProgId("Sample.Control") class SampleControl extends UserControl { private var textName: TextBox; private var labelName: Label; private var components: IContainer; public function SampleControl() { InitializeComponent(); } public function InitializeComponent(): void { components = new System.ComponentModel.Container(); textName = new TextBox(); labelName = new Label(); textName.Location = new Point(64, 8); textName.Size = new System.Drawing.Size(240, 23); textName.TabIndex = 0; labelName.Location = new Point(8, 8); labelName.Size = new System.Drawing.Size(56, 23); labelName.Text = "Name:"; labelName.TextAlign = ContentAlignment.MiddleRight; Controls.AddRange(Control[]([labelName, textName])); Size = new System.Drawing.Size(300, 80); } public function get Value(): String { return textName.Text; } public function set Value(val: String) { textName.Text = val; } }
バッチではこんなの FOR /F "delims=" %%1 IN ('DIR /AD /B /ON "%SystemRoot%\Microsoft.NET\Framework\v*"') DO SET DOTNET=%%~1 ECHO "%SystemRoot%\Microsoft.NET\Framework\%DOTNET%\jsc.exe"
これでどうでしょう @ECHO OFF SETLOCAL SET Framework=%SystemRoot%\Microsoft.NET\Framework FOR /F "delims=" %%1 IN ('DIR /AD /B /ON "%SystemRoot%\Microsoft.NET\Framework\v*"') DO IF EXIST "%Framework%\%%~1\jsc.exe" set DOTNET=%%~1 SET JSC="%Framework%\%DOTNET%\jsc.exe" ECHO %JSC%
117 名前:115 mailto:sage [2007/02/05(月) 18:51:59 ]
>>116の4行目は↓でok FOR /F "delims=" %%1 IN ('DIR /AD /B /ON "%Framework%\v*"') DO IF EXIST "%Framework%\%%~1\jsc.exe" set DOTNET=%%~1
コンソールのタイトルを表示するバッチファイル+JScript.NET @if(0)==(0) ECHO OFF SETLOCAL SET DOTNET=%SystemRoot%\Microsoft.NET\Framework FOR /F "delims=" %%1 IN ('DIR /AD /B /ON "%DOTNET%\v*"') DO IF EXIST "%DOTNET%\%%~1\jsc.exe" SET DOTNET=%DOTNET%\%%~1\jsc.exe "%DOTNET%" /nologo /d:_ /out:"%~f0.exe" "%~f0" "%~f0.exe" DEL "%~f0.exe" GOTO :EOF @end import System; import System.Diagnostics; var PC : PerformanceCounter=new PerformanceCounter('Process','Creating Process Id',Process.GetCurrentProcess().ProcessName); var PID : int = PC.RawValue; Console.WriteLine(Process.GetProcessById(PID).MainWindowTitle) ワーンングが出ますが、コードのほうで直せませんか?
>>119 サンクス。直りました。今度は最小化ですが、 import System; import System.Diagnostics; import System.Windows.Forms; const WM_SYSCOMMAND : int = 0x0112; const SC_MINIMIZE : int = 0xF020; var nCmdShow : int =SC_MINIMIZE; var PC : PerformanceCounter=new PerformanceCounter('Process','Creating Process Id',Process.GetCurrentProcess().ProcessName); var PID : int=int(PC.RawValue); var oProcess : System.Diagnostics.Process=System.Diagnostics.Process.GetProcessById(PID); var hwnd : IntPtr=oProcess.MainWindowHandle; var m : Message = Message.Create(hwnd,WM_SYSCOMMAND,IntPtr.op_Explicit(nCmdShow),IntPtr.op_Explicit(0)); var nw : NativeWindow = new NativeWindow(); nw.AssignHandle(hwnd); print(m.ToString()); nw.DefWndProc(m); // 型が一致しません。のエラーになります。なぜでしょう? nw.ReleaseHandle(); nw = null;