// CalcSample

var obj;
obj = new ActiveXObject("SeraphyScriptDialog");

function main()
{
	var frm;
	frm = obj.CreateForm();
	frm.FormTitle = "スクリプト式電卓 LimitedEdition";
	frm.DefineLabel("ステータス");
	var ia = frm.DefineEdit("A=","10");
	var ib = frm.DefineEdit("B=","20");
	var ic = frm.DefineEdit("C=");
	var b1 = frm.DefineButton("クリア");
	frm.DefineLabel("コマンド入力欄");
	var id = frm.DefineEdit(null, "c = a + b\r\nc = c * 2", 5);
	var cmd = 100;
	frm.DefineButton("実行;終了", cmd);

	frm.ComposeForm();
	do{
		var retEvent = frm.WaitEvent(10000); // ウェイトの量は大きくても問題ない。
		if (retEvent == b1) {
			frm.Value(ia) = 0;
			frm.Value(ib) = 0;
			frm.Value(ic) = 0;
		}
		if (retEvent == cmd) {
			var a,b,c,scr;
			a = Number(frm.Value(ia));
			b = Number(frm.Value(ib));
			c = Number(frm.Value(ic));
			scr = frm.Value(id);
			eval(scr);
			frm.Value(ia) = a;
			frm.Value(ib) = b;
			frm.Value(ic) = c;
		}
	} while (retEvent != -1 && retEvent != cmd + 1);
	frm.DestroyForm();
}

main();
