xyl006 发表于 2008-9-19 18:39:04

好像很简单,但俺不懂

Auto It 能不能实现以下要求,请大家指点。
有运行与停止两个按钮,点击运行,程序就开始运行。点击停止,程序就停止。

huangke 发表于 2008-9-19 19:30:09

停止的意思是关闭吗?这样很容易的..

xyl006 发表于 2008-9-19 19:45:29

我用了以下代码,但不行

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 473, 141, 1643, 207)
$Progress1 = GUICtrlCreateProgress(15, 72, 433, 41)
$Button1 = GUICtrlCreateButton("Run", 48, 16, 121, 41, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
$Button2 = GUICtrlCreateButton("Stop", 280, 16, 121, 41, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$mdb_data_path="D:\home\Training\ASPX\CCC\SCVData\DataAdmin.mdb"

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                       
                        While 1
                               
                                       
                               
                                ;MsgBox(0,"test","hello")
                               
                                du()

                                $nMsg = GUIGetMsg()
                                Switch $nMsg
                                        Case $GUI_EVENT_CLOSE
                                                Exit
                                        case $Button2
                                                ExitLoop
                                EndSwitch
                                Sleep(30000)
                        WEnd

                Case $Button2
                        ;Exit
        EndSwitch
WEnd

Func du()

                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path)
                $RS =ObjCreate("ADODB.Recordset")
                $RS.ActiveConnection = $addfld
                $RS.Open ("Select * From test where runFlag='Y'")
                while Not $RS.eof And Not $RS.bof
         if @error =1 Then ExitLoop
            ;GUICtrlCreateListViewItem ( $RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value,$ListView1 )
                        $sQuery ="update test setrunFlag='N' WHERE uid="& $RS.Fields(0).value
                        $addfld.execute($sQuery)
                        ;$RS("runFlag")="N"
                        ;$rs.update       
                        MsgBox(0, "", $RS.Fields (2).value);显示表第一个数据
                        $rs.movenext
                WEnd
                $rs.close
                $addfld.Close
EndFunc

netegg 发表于 2008-9-20 11:47:03

这么写似乎不行吧,你把里面的那个switsh,另外,你那个界面的坐标似乎不对吧

liongodmien 发表于 2008-9-27 11:34:26

$Form1 = GUICreate("Form1", 473, 141, 1643, 207)按这一句看,你的屏幕真的是很宽啊!!!


While 1
                              
                                       
                              
                              ;MsgBox(0,"test","hello")
                              
                              du()

                              $nMsg = GUIGetMsg()
                              Switch $nMsg
                                        Case $GUI_EVENT_CLOSE
                                                Exit
                                        case $Button2
                                                ExitLoop
                              EndSwitch
                              ;Sleep(30000)  这个Sleep 加的相当无聊啊!帮助没看清!
                        WEnd

修改后可以正常运行的:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 473, 141)
$Progress1 = GUICtrlCreateProgress(15, 72, 433, 41)
$Button1 = GUICtrlCreateButton("Run", 48, 16, 121, 41, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
$Button2 = GUICtrlCreateButton("Stop", 280, 16, 121, 41, 0)
GUICtrlSetFont(-1, 10, 800, 0, "Verdana")
GUISetState()
#EndRegion ### END Koda GUI section ###
;$mdb_data_path="D:\home\Training\ASPX\CCC\SCVData\DataAdmin.mdb"

While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        While 1
                            ;MsgBox(0,"test","hello")
                              du()
                              $nMsg = GUIGetMsg()
                              Switch $nMsg
                                        Case $GUI_EVENT_CLOSE
                                                                                        Exit
                                                                                case $Button2
                                                                                        ToolTip("")
                                                                                        ExitLoop
                              EndSwitch
                              ;Sleep(30000)注意不要有这个!
                        WEnd

                Case $Button2
                        Exit
      EndSwitch
WEnd

Func du()
ToolTip("测试运行..." & @SEC)
                ;$addfld = ObjCreate("ADODB.Connection")
                ;$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path)
                ;$RS =ObjCreate("ADODB.Recordset")
                ;$RS.ActiveConnection = $addfld
                ;$RS.Open ("Select * From test where runFlag='Y'")
                ;while Not $RS.eof And Not $RS.bof
         ;if @error =1 Then ExitLoop
            ;GUICtrlCreateListViewItem ( $RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value,$ListView1 )
            ;            $sQuery ="update test setrunFlag='N' WHERE uid="& $RS.Fields(0).value
             ;         $addfld.execute($sQuery)
            ;          ;$RS("runFlag")="N"
                        ;$rs.update      
                ;      MsgBox(0, "", $RS.Fields (2).value);显示表第一个数据
               ;         $rs.movenext
                ;WEnd
             ;   $rs.close
            ;$addfld.Close
EndFunc


[ 本帖最后由 liongodmien 于 2008-9-27 11:36 编辑 ]

lcgkogoo 发表于 2008-9-27 14:09:54

顶了..学习学习!
页: [1]
查看完整版本: 好像很简单,但俺不懂