「マクロ覚え書き(開発者向け)」の版間の差分
プログラミング言語名の修正 |
ソースコードの整形 |
||
| 21行目: | 21行目: | ||
ただし読み込む側が FileSystemObject を利用している場合、SJIS/Unicode しか対応できないのでその場合は SJIS をお勧めします(Mery 1 時代のマクロなどはコレです)。 | ただし読み込む側が FileSystemObject を利用している場合、SJIS/Unicode しか対応できないのでその場合は SJIS をお勧めします(Mery 1 時代のマクロなどはコレです)。 | ||
== window.Document と | == window.Document と editor.ActiveDocument の違い == | ||
window.Document は、マクロ開始時にアクティブなドキュメントを指し続けます。マクロで別のドキュメントを Activate しても変わりません。 | window.Document は、マクロ開始時にアクティブなドキュメントを指し続けます。マクロで別のドキュメントを Activate しても変わりません。 | ||
editor.ActiveDocument は、その時点でアクティブなドキュメントを指します。マクロで別のドキュメントを Activate すると当然変わります。 | |||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
editor.documents.Item(0).Activate(); | |||
Alert( | Alert(document.Name); | ||
Alert( | Alert(editor.ActiveDocument.Name); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
また、window.Document は | また、window.Document は documents.Item() と一致しませんが、editor.ActiveDocument は一致します。 | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
for (var i = 0; i < | for (var i = 0; i < editor.documents.Count; i++) { | ||
if ( | if (editor.ActiveDocument == editor.documents.Item(i)) { | ||
Alert(" | Alert("editor.ActiveDocument が一致"); | ||
} | } | ||
if (Document == | if (Document == editor.documents.Item(i)) { | ||
Alert("window.Document が一致"); | Alert("window.Document が一致"); | ||
} | } | ||
| 66行目: | 66行目: | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
var | var sel = document.selection; | ||
var isBoxed = ( | var isBoxed = (sel.GetBottomPointY(mePosView) - sel.GetTopPointY(mePosView)) != (sel.Text.match(/\n/g) || []).length; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| 76行目: | 76行目: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | == document.GetLines の引数 == | ||
リファレンスには meGetLineView しか書かれていませんが、論理行単位での行数取得には引数に 0 を渡します。 | リファレンスには meGetLineView しか書かれていませんが、論理行単位での行数取得には引数に 0 を渡します。 | ||
| 120行目: | 120行目: | ||
// ファイルの読み込み | // ファイルの読み込み | ||
var fsIn = fso.OpenTextFile( | 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( | adodb.LoadFromFile(document.FullName); | ||
var text = adodb.ReadText(adReadAll); | var text = adodb.ReadText(adReadAll); | ||
adodb.Close(); | adodb.Close(); | ||
| 175行目: | 175行目: | ||
// ファイルの読み込み | // ファイルの読み込み | ||
var text = IO.LoadFromFile( | var text = IO.LoadFromFile(document.FullName, "utf-8"); | ||
Alert(text); | Alert(text); | ||
スポンサーリンク