kun
1
안녕하세요. ctrl+f (찾기)를 이용해서 파란색 문자열([야구])을 찾고 그 다음 복잡한 작업을 하는
매크로를 만들고 있습니다.
그런데 while문에서 막혀서 질문을 드립니다.
제가 알기로는 찾기 실행 시
HAction.Execute(“RepeatFind”, HParameterSet.HFindReplace.HSet);
는 true 값을 리턴하다가
마지막에 더 찾을 값이 없으면 false를 리턴하는 것으로 아는데
제 코드에 적용 했을때는 true 값만 리턴하여 무한 루프에 빠집니다.
찾기를 잘못 사용하고 있는 걸까요 ?
방법을 아시는 분들께 조언을 구합니다.
function OnDocument_New() {
while (findBlue()) {
HAction.Run(“MoveParaEnd”);
// false가 안 떠요 ㅠㅜ
}
}
function findBlue() {
HAction.GetDefault(“FindDlg”, HParameterSet.HFindReplace.HSet);
with (HParameterSet.HFindReplace)
{
MatchCase = 0;
AllWordForms = 0;
SeveralWords = 0;
UseWildCards = 0;
WholeWordOnly = 0;
AutoSpell = 1;
Direction = 0;
IgnoreFindString = 0;
IgnoreReplaceString = 0;
FindString = “[야구]”;
ReplaceString = “”;
FindCharShape.TextColor = RGBColor(0, 0, 255);
IgnoreMessage = 1;
HanjaFromHangul = 0;
FindJaso = 0;
FindRegExp = 0;
FindStyle = “”;
ReplaceStyle = “”;
}
HAction.Execute(“FindDlg”, HParameterSet.HFindReplace.HSet);
HAction.GetDefault(“RepeatFind”, HParameterSet.HFindReplace.HSet);
with (HParameterSet.HFindReplace) {
FindCharShape.TextColor = RGBColor(0, 0, 255);
ReplaceString = “”;
FindString = “[야구]”;
IgnoreReplaceString = 0;
IgnoreFindString = 0;
Direction = FindDir(“Forward”);
WholeWordOnly = 0;
UseWildCards = 0;
SeveralWords = 0;
AllWordForms = 0;
MatchCase = 0;
ReplaceMode = 0;
ReplaceStyle = “”;
FindStyle = “”;
FindRegExp = 0;
FindJaso = 0;
HanjaFromHangul = 0;
IgnoreMessage = 1;
FindType = 1;
}
theEnd = HAction.Execute(“RepeatFind”, HParameterSet.HFindReplace.HSet);
return theEnd;
}
안녕하세요.
작성하신 코드를 실행하면 무한 루프에 빠집니다.
스크립트로 실행하면 문서 끝까지 검색 후에 메시지 박스를 띄우지 않기 때문에
문서 끝까지 찾은 후에도 true가 반환됩니다. ![:thinking: :thinking:](https://emoji.discourse-cdn.com/twitter/thinking.png?v=12)
그래서 아래와 같은 방법을 제안해드립니다.
문서 끝까지 검색 후에 위치가 처음 위치로 이동하는 것을 착안하여,
function findBlue() {
HAction.GetDefault("FindDlg", HParameterSet.HFindReplace.HSet);
with (HParameterSet.HFindReplace)
{
MatchCase = 0;
AllWordForms = 0;
SeveralWords = 0;
UseWildCards = 0;
WholeWordOnly = 0;
AutoSpell = 1;
Direction = 0;
IgnoreFindString = 0;
IgnoreReplaceString = 0;
FindString = "[야구]";
ReplaceString = "";
FindCharShape.TextColor = RGBColor(0, 0, 255);
IgnoreMessage = 0;
HanjaFromHangul = 1;
FindJaso = 0;
FindRegExp = 0;
FindStyle = "";
ReplaceStyle = "";
}
HAction.Execute("FindDlg", HParameterSet.HFindReplace.HSet);
HAction.GetDefault("RepeatFind", HParameterSet.HFindReplace.HSet);
with (HParameterSet.HFindReplace) {
FindCharShape.TextColor = RGBColor(0, 0, 255);
ReplaceString = "";
FindString = "[야구]";
IgnoreReplaceString = 0;
IgnoreFindString = 0;
Direction = FindDir("Forward");
WholeWordOnly = 0;
UseWildCards = 0;
SeveralWords = 0;
AllWordForms = 0;
MatchCase = 0;
ReplaceMode = 0;
ReplaceStyle = "";
FindStyle = "";
FindRegExp = 0;
FindJaso = 0;
HanjaFromHangul = 0;
IgnoreMessage = 1;
FindType = 1;
}
theEnd = HAction.Execute("RepeatFind", HParameterSet.HFindReplace.HSet);
return theEnd;
}
function OnScriptMacro_script1()
{
// 문서의 시작 위치로 이동
Run("MoveDocBegin");
// 시작 위치를 저장
var sPosSet = GetPosBySet();
var slist = sPosSet.Item("List");
var spara = sPosSet.Item("Para");
var spos = sPosSet.Item("Pos");
while (true) {
findBlue();
// 찾은 후에 현재 위치를 구함
var cPosSet = GetPosBySet();
var clist = cPosSet.Item("List");
var cpara = cPosSet.Item("Para");
var cpos = cPosSet.Item("Pos");
// 문서를 끝까지 검색 후에 검색 위치가 처음으로 위치가 이동하기에 현재 위치와 처음 위치를 비교하여 빠져나옴
if (slist == clist && spara == cpara && spos == cpos) {
break;
}
//HAction.Run("MoveParaEnd");
// false가 안 떠요 ㅠㅜ
}
}
해보시고 안되는 부분이 있으면 다시 코멘트 부탁드립니다.
감사합니다.
1개의 좋아요