「マクロ覚え書き(開発者向け)」の版間の差分

MSY-07 (トーク | 投稿記録)
プログラミング言語名の修正
MSY-07 (トーク | 投稿記録)
ソースコードの整形
21行目: 21行目:
ただし読み込む側が FileSystemObject を利用している場合、SJIS/Unicode しか対応できないのでその場合は SJIS をお勧めします(Mery 1 時代のマクロなどはコレです)。
ただし読み込む側が FileSystemObject を利用している場合、SJIS/Unicode しか対応できないのでその場合は SJIS をお勧めします(Mery 1 時代のマクロなどはコレです)。


== window.Document と Editor.ActiveDocument の違い ==
== window.Document と editor.ActiveDocument の違い ==
window.Document は、マクロ開始時にアクティブなドキュメントを指し続けます。マクロで別のドキュメントを Activate しても変わりません。
window.Document は、マクロ開始時にアクティブなドキュメントを指し続けます。マクロで別のドキュメントを Activate しても変わりません。


Editor.ActiveDocument は、その時点でアクティブなドキュメントを指します。マクロで別のドキュメントを Activate すると当然変わります。
editor.ActiveDocument は、その時点でアクティブなドキュメントを指します。マクロで別のドキュメントを Activate すると当然変わります。


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
Editor.Documents.Item(0).Activate();
editor.documents.Item(0).Activate();
Alert(Document.Name);
Alert(document.Name);
Alert(Editor.ActiveDocument.Name);
Alert(editor.ActiveDocument.Name);
</syntaxhighlight>
</syntaxhighlight>


また、window.Document は Documents.Item() と一致しませんが、Editor.ActiveDocument は一致します。
また、window.Document は documents.Item() と一致しませんが、editor.ActiveDocument は一致します。


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
for (var i = 0; i < Editor.Documents.Count; i++) {
for (var i = 0; i < editor.documents.Count; i++) {
if (Editor.ActiveDocument == Editor.Documents.Item(i)) {
if (editor.ActiveDocument == editor.documents.Item(i)) {
Alert("Editor.ActiveDocument が一致");
Alert("editor.ActiveDocument が一致");
}
}
if (Document == Editor.Documents.Item(i)) {
if (Document == editor.documents.Item(i)) {
Alert("window.Document が一致");
Alert("window.Document が一致");
}
}
66行目: 66行目:


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
var s = Document.Selection;
var sel = document.selection;
var isBoxed = (s.GetBottomPointY(mePosView) - s.GetTopPointY(mePosView)) != (s.Text.match(/\n/g) || []).length;
var isBoxed = (sel.GetBottomPointY(mePosView) - sel.GetTopPointY(mePosView)) != (sel.Text.match(/\n/g) || []).length;
</syntaxhighlight>
</syntaxhighlight>


76行目: 76行目:
</syntaxhighlight>
</syntaxhighlight>


== Document.GetLines の引数 ==
== document.GetLines の引数 ==
リファレンスには meGetLineView しか書かれていませんが、論理行単位での行数取得には引数に 0 を渡します。
リファレンスには meGetLineView しか書かれていませんが、論理行単位での行数取得には引数に 0 を渡します。


120行目: 120行目:


// ファイルの読み込み
// ファイルの読み込み
var fsIn = fso.OpenTextFile(Document.FullName, ForReading, false, TristateUseDefault);
var fsIn = fso.OpenTextFile(document.FullName, ForReading, false, TristateUseDefault);
var text = fsIn.ReadAll();
var text = fsIn.ReadAll();
fsIn.Close();
fsIn.Close();
149行目: 149行目:
adodb.Charset = 'utf-8';
adodb.Charset = 'utf-8';
adodb.Open();
adodb.Open();
adodb.LoadFromFile(Document.FullName);
adodb.LoadFromFile(document.FullName);
var text = adodb.ReadText(adReadAll);
var text = adodb.ReadText(adReadAll);
adodb.Close();
adodb.Close();
175行目: 175行目:


// ファイルの読み込み
// ファイルの読み込み
var text = IO.LoadFromFile(Document.FullName, "utf-8");
var text = IO.LoadFromFile(document.FullName, "utf-8");
Alert(text);
Alert(text);


スポンサーリンク