2013-08-31 87 views
1

我有一个脚本,用于输入记录在我们的系统中最初正常工作与MsgBox,但我添加了一个GUI来显示记录条目。现在脚本在第一条记录后停止。循环,读取后停止一个记录与GUI(不循环)

在下面的例子中,我已经删除了所有的操作和记录行,以帮助更容易解析,但是我保留了所有重要的东西并测试了此版本的脚本。

Loop, read, C:\_AutoHotKey\AA_test.txt 
{ 
    StringSplit, LineArray, A_LoopReadLine, %A_Tab% 

    aaduedate := LineArray1 
    aauniqueid := LineArray2 
    aaprefix := LineArray3 
    aasequence := LineArray4 
    aadescript := LineArray5 
    aaelig  := LineArray6 

;------------------------------------------------------------------------------------- 
;Use these to test the file match in the Input File. 
;Remove surrounding comments and surround the rest of the script up to the last brace. 
    SendInput, Prefix: %aaprefix% {enter} 
    SendInput, Sequence: %aasequence% {enter} 
    SendInput, Description: %aadescript% {enter} 
    SendInput, Eligibility: %aaelig% {enter} 
    SendInput, ID Card: %aaidcard% {enter} 
;--------------------------------------------------------------------------------------- 

;Pop-up validation menu 
Gui, Add, Button, x22 y380 w100 h30 , &Submit 
Gui, Add, Button, x362 y380 w100 h30 , &Cancel 
Gui, Font, S14 CDefault, Verdana 
Gui, Add, Text, x152 y10 w210 h30 +Center, Is the entry correct? 
Gui, Font, S10 CDefault, Verdana 
Gui, Add, Text, x102 y40 w90 h20 , %aaprefix% 
Gui, Add, Text, x102 y70 w130 h20 , %aaelig% 
Gui, Add, Text, x312 y70 w30 h20 , %aadescript% 
Gui, Add, Text, x432 y70 w30 h20 , %aaidcard% 
Gui, Font, S8 CDefault, Verdana 
Gui, Add, Text, x132 y380 w230 h40 +Center, Click Submit/press S to continue. Click cancel to stop script. 
; Generated using SmartGUI Creator 4.0 
Gui, Show, x9 y250 h428 w480, Auto Action Validation 
Return 

ButtonCancel: 
ExitApp 

ButtonSubmit: 
Gui, Submit ; 
    MouseMove, 630,55 
    Sleep, 100 
    SendInput, {Click 630,55} 
    SendInput ^S 

Return 

} 

这些按钮可以工作,点击提交将发送MouseMove和SendInput。但在此之后,它会停止并且不会加载文本文件中的下一条记录。

在此先感谢!

回答

0

你在循环中有一个返回命令。

这退出程序

看到这个例子。 该循环应运行5次,但返回 命令在第一次运行后停止。

Loop, 5 
{ 
    msgbox, %A_Index% 
    return 
} 
+0

这种编程方法存在的问题是,如果您遗漏了 * return *命令,则循环不会暂停。所以这也行不通。更好的方法是编写一个函数 ,它只读取列表中的下一个项目并键入它。然后,您可以将该GUI从循环中打开并在每次确认输入时调用此函数。这有点棘手。如果您是初学者,如果您在循环中打开带有“是/否”按钮的消息框,则可能会获得更多成功。 – 576i

+0

啊。射击。那么,我是一个初学者,但是,我还需要有记录显示供用户验证。所以,它看起来像我将学习如何将GUI退出循环。 谢谢! (如果您有任何提示,我应该在帮助中寻求帮助,这将不胜感激。) – user2734945

+0

我已经想出了如何使这项工作,并仍然获得显示记录的GUI。我将提交和取消按钮从GUI中取出,并将MsgBox带回。如果MsgBox评估为yes,则会销毁GUI。 我的下一个评论中有代码,还有一些小东西可以将消息框移开。 – user2734945

0

我能得到这个从GUI删除提交按钮,将它移动到一个MsgBox工作。

图形用户界面基本上是一样的,但提交和取消行已被删除以及后面的返回和所有逻辑。

接下来,添加一个MsgBox来确认数据。这现在使用GUI来显示记录的内容和MsgBox以确认并移动到下一个记录。

另外,我偷了一些代码(并且不太了解),它移动了MsgBox,以便它不会阻止接收应用程序中的数据输入屏幕。

下面是新的代码,经过桂秀,X9取代一切......

OnMessage(0x44, "WM_COMMNOTIFY") 
MsgBox 4, AA Entry, Would you like to continue? (press Yes or No) 

WM_COMMNOTIFY(wParam) { 
    if (wParam = 1027) { ; AHK_DIALOG 
     Process, Exist 
       DetectHiddenWindows, On 
     if WinExist("ahk_class #32770 ahk_pid " . ErrorLevel) { 
      WinGetPos,,, w 
      WinMove, 90, 650 
     } 
    } 
    } 
;If the user responds yes, then close the Gui (Destroy) and enter the record 
IfMsgBox Yes 
    { 
     Gui destroy 
     Sleep, 100 
} 
    else 
     ExitApp 

} 

谢谢,我希望这是有益的人。