Jump to content

Stop script without closing program...


jfcby
 Share

Recommended Posts

Hi,

Is it possible to to stop a script from running without closing the program? Example: Exit and ExitLoop closes the program.

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

  • Developers

Maybe you need to reread your question assuming you haven't read it before. :)

Define Stop or do you mean you want the script to pause?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi,

Is it possible to to stop a script from running without closing the program? Example: Exit and ExitLoop closes the program.

Thank you for your help,

jfcby

A little code might help. Right now your problem is pretty vague so hard to help you.

Link to comment
Share on other sites

Maybe you need to reread your question assuming you haven't read it before. :)

Define Stop or do you mean you want the script to pause?

Maybe I'm defining and understanding stop wrong according to script writing.

I define stop as when the script is running and some data was not entered correctly and I need to stop the script not exit the script to make the changes and then continue running the script.

#include <Word.au3>
#include <Math.au3>
#include <ExcelCOM_UDF.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Dim $GUI, $sObjName, $fDisplayAlerts, $fScreenUpdating
Dim $wwdth, $whght, $mpX, $mpY
Dim $btn_FF, $btn_EquipListFF, $btn_Insert, $btn_Next, $btn_Previous, $msg
Dim $ffSignin, $fPath1, $fPath2, $fpath3, $sFilePath1, $sFilePath2
Dim $nrow, $lrow, $startcell, $lastcell
Dim $filemenu, $exititem, $btn_Exit

$ffSignin = "http://ff.ppd.uga.edu/Citrix/AccessPlatform/auth/login.aspx"
$fPath1 = @HomeDrive & "\Documents and Settings\All Users\Documents\FFPM\"
$fPath2 = "Equip_List_FF.xls"
$fpath3 = "Equip_List_FF.exe"
$wbkEquipListFF = $fPath1 & $fPath2
$sFilePath1 = $fPath1 & $fPath2;@ScriptDir & "\Test1.xlsx"
$sFilePath2 = "";@ScriptDir & "\Test2.xlsx"
$wwdth = 350
$whght = 425
$mpX = 650
$mpY = 100
$GUI = GUICreate("Data AppInserter", $wwdth, 225); will create a dialog box that when displayed is centered
HotKeySet("{ESC}", "_Quit")
;Opt("GUICoordMode", 2)

;Main Label Control
$SS_CENTER = "0x01"
;Main Label Title
$fBold = "Arial Bold"
GUISetFont(9, 400, 4, $fBold)
GUICtrlCreateLabel("Enter Data Into Facility Focus(FF) Form Excel File.", 5, 10, 345, 15, $SS_CENTER)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER + $GUI_DOCKVCENTER + $GUI_DOCKSIZE + $GUI_DOCKALL)

;Main Label Description
$fCourier_New = "Courier New"
GUISetFont(9, 400, 1, $fCourier_New)
GUICtrlCreateLabel("To enter data into FF PM Module Inventory Management from an Excel File Equip_List_FF.xls follow the steps below.", 5, 50, 345, 75, $SS_CENTER)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

;FF Signin
$fArial = "Arial"
GUISetFont(9, 400, 1, $fArial)
;GuiCtrlCreateGroup("STEP 1", 2, 115, 345, 30)
GUICtrlCreateLabel("STEP 1: Signin To Facility Focus", 5, 125, 200, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$btn_FF = GUICtrlCreateButton("Signin", 235, 125, 75, 25);Left, Down, Width, Height
GUICtrlSetResizing($btn_FF, $GUI_DOCKALL)
;Open Equip_List_FF.xls
GUICtrlCreateLabel("STEP 2: Open Equip_List_FF.xls File", 5, 155, 215, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$btn_EquipListFF = GUICtrlCreateButton("Open", 235, 155, 75, 25)
GUICtrlSetResizing($btn_EquipListFF, $GUI_DOCKALL)
;Insert Data into FF
GUICtrlCreateLabel("STEP 3: Insert Data into FF", 5, 185, 160, 25)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$btn_Insert = GUICtrlCreateButton("Insert", 235, 185, 75, 25)
GUICtrlSetResizing($btn_Insert, $GUI_DOCKALL)

GUISetState(); will display an dialog box with 3 button

; Run the GUI until the dialog is closed
Opt('MustDeclareVars', 1)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $btn_FF
    ; Run/Open FF Signin Webpage
            ShellExecute($ffSignin)

            #cs -----Will be added as a feature update in next revision----------
        ; Activate/Set focus to FF Inventory Management Window
                winFInv()
                
                Send("{ALT}")
                Send("{RIGHT 2}")
                Send("{DOWN 2}")
                Send("{Right}")
                Send("{ENTER}")
                MouseClick("left", 134, 65)
                
                Sleep(2000)
                
        ;Activate the Data Inserter Application Window
                winDataInserter()
            #ce ------------------------------------------------------------------------
            
        Case $msg = $btn_EquipListFF
    ;Run/Open Microsoft Excel Workbook: Equip_List_FF.xls
            ShellExecute($wbkEquipListFF)
            
        Case $msg = $btn_Insert
    ;MsgBox(0, 'Insert', 'Inserting Data')
    ;Check if Excel Workbook Equip_List_FF.xls is open
            _WordErrorHandlerRegister()
            Dim $oExcel1 = _ExcelBookAttach($sFilePath1, "FilePath")
            Dim $oExcel2 = _ExcelBookAttach($sFilePath2, "FilePath")
            
            Sleep(2000)

    ;Set columns & rows that do not change
            Dim $startcell, $lastcell, $nrow, $lrow, $nrowM, $btn_SetRows, $lrowM, $st1, $msg2
    ;http://www.autoitscript.com/forum/index.php?showtopic=62427&hl=_ExcelSheetUsedRangeGet
    ;Start Row
            $startcell = "4"
    ;Last Row with data
            $lastcell = $oExcel1.Application.Selection.SpecialCells($xlCellTypeLastCell).Row;Address
    ;MsgBox(0, "","Last Cell With Data: " & $lastcell & " -- Start Row: " & $startcell)

            #cs - Loop through Options:
                option 1. Change start and last rows
                option 2. Loop through Excel_List_FF.xls ActiveWorksheet and insert data in FF
                option 3. Continue with another worksheet or exit
            #ce
            For $opt = 1 To 3
                If $opt = 1 Then
            ;Inputboxes to change start  and last row
                    GUICtrlCreateLabel("Change Start Row", 20, 225, 110, 25)
                    GUICtrlSetResizing(-1, $GUI_DOCKALL)
                    $nrow = GUICtrlCreateInput($startcell, 135, 225, 75, 25)
                    GUICtrlSetResizing($nrow, $GUI_DOCKALL)
                    GUICtrlCreateLabel("Change Last Row", 20, 260, 110, 25)
                    GUICtrlSetResizing(-1, $GUI_DOCKALL)
                    $lrow = GUICtrlCreateInput($lastcell, 135, 260, 75, 25)
                    GUICtrlSetResizing($lrow, $GUI_DOCKALL)
                    $btn_SetRows = GUICtrlCreateButton("Set Rows", 235, 260, 75, 25);Left, Down, Width, Height
                    GUICtrlSetResizing($btn_SetRows, $GUI_DOCKALL)
            ;GUICtrlSetResizing($btn_SetRows, $GUI_DOCKHCENTER + $GUI_DOCKVCENTER)
            ;_WinAPI_SetWindowPos($hWnd, $hAfter, $iX, $iY, $iCX, $iCY, $iFlags)
                    _WinAPI_SetWindowPos($GUI, $HWND_TOPMOST, 500, 500, 350, 350, $SWP_NOMOVE)
                    
                    Do
                        $msg2 = GUIGetMsg()
                        Select
                            Case $msg2 = $GUI_EVENT_CLOSE
                                Exit
                            Case $msg2 = $btn_SetRows
                                $nrowM = GUICtrlRead($nrow)
                                $lrowM = GUICtrlRead($lrow)
                        ;MsgBox(0, "", "$nrowM = " & $nrowM & " - " & "$lrowM = " & $lrowM)
                        EndSelect
                    Until $msg2 = $btn_SetRows
                ElseIf $opt = 2 Then
                    Dim $sCellValue1, $sCellValue2, $sCellValue3, $sCellValue4, $sCellValue6, $sCellValue7
                    Dim $msg3
            ;Insert Next Part
                    _WinAPI_MoveWindow($GUI, $mpX, $mpY, $wwdth, $whght);moves window to upper right corener
                    WinSetOnTop("Data AppInserter", "", 1);window stays on top
                    GUICtrlCreateLabel("Insert Next Part", 100, 315, 125, 25)
                    $btn_Next = GUICtrlCreateButton("Next", 235, 315, 75, 25);Left, Down, Width, Height
                    GUICtrlCreateLabel("ReInsert Previous Part", 100, 350, 125, 25)
                    $btn_Previous = GUICtrlCreateButton("Previous", 235, 350, 75, 25)
            ;MsgBox(0, "", "$nrowM = " & $nrowM & " - " & "$lrowM = " & $lrowM)
            ;MsgBox(0, "", "The Cell Value is: " &  @CRLF & $sCellValue1);& @CRLF & $sCellValue5 & @CRLF & $sCellValue6, )
                    $sCellValue1 = StringTrimLeft(_ExcelReadCell($oExcel1, 2, 3), 7);bldgno
                    For $i = $nrowM To $lrowM;Loop
                        $sCellValue2 = _ExcelReadCell($oExcel1, $i, 2);serialno
                        $sCellValue3 = _ExcelReadCell($oExcel1, $i, 3);ffinvpart & Equipment
                        $sCellValue4 = _ExcelReadCell($oExcel1, $i, 4);description
                        $sCellValue6 = _ExcelReadCell($oExcel1, $i, 6);roomno
                        $sCellValue7 = _ExcelReadCell($oExcel1, $i, 7);extradesc or notes
                        Do
                            $msg3 = GUIGetMsg()
                            Select
                                Case $msg3 = $GUI_EVENT_CLOSE
                                    Exit
                                Case $msg3 = $btn_Next Or $msg3 = $btn_Previous
                                    If $msg3 = $btn_Previous Then
                                        $i = $i - 2
                                        _GUICtrlButton_Enable($btn_Previous, False);Disables Previous Button
                                    Else
                                ;Call Function to Activate/maximize FF Inventory Management - \\Remote window
                                        winFFInv()
                                ;Click Insert
                                ; Click in FF Equipment Field
                                        MouseClick("left", 114, 135)
                                ; Now that the Notepad window is active type some special characters
                                        Send($sCellValue3 & "{ENTER}");invpart & Equipment
                                        Sleep(2000)
                                        Send($sCellValue1 & "-" & $sCellValue2 & "{ENTER 2}");serialno
                                        Sleep(2000)
                                        Send($sCellValue4 & "{ENTER 2}");description
                                        Sleep(2000)
                                        Send("U" & "{ENTER 7}");status
                                        Sleep(2000)
                                        Send("16" & "{ENTER 4}");shop
                                        Sleep(2000)
                                        Send($sCellValue1 & "{ENTER}");bldgno
                                    ;Closes Property Notes - \\Remote if opens
                                            Sleep(1000)                                     
                                            If WinExists("Property Notes - \\Remote") Then 
                                                WinActivate("Property Notes - \\Remote", "")
                                                Send("!C")
                                            EndIf
                                        
                                            Sleep(2000)
                                            Send($sCellValue6);loc

                                            If $sCellValue7 > "" Then
                                                Sleep(2000)
                                        ; Click the Extra Description Box
                                                MouseClick("left", 516, 210)
                                        ;Extra Description Box Text
                                                Send($sCellValue7)
                                                Sleep(2000)
                                                Send("!C{ENTER}")

                                                _GUICtrlButton_Enable($btn_Previous);Disables Previous Button
                                            EndIf
                                        EndIf
                                EndSelect
                            Until $msg3 = $btn_Next Or $msg3 = $btn_Previous
                        Next
                    Else;Option to continue with another worksheet or exit
                        GUISetState(@SW_HIDE)
                ;Function to continue or exit
                        _ContExt($fPath1, $fpath3)
                        Sleep(1000)
                ;Function to quit/exit this program
                        _Quit()
                    EndIf
                Next
        EndSelect
    WEnd

;_ExcelBookClose1($oExcel1, 0)
;Sleep(5000)
;_ExcelBookClose1($oExcel2, 0)

    Func _Quit()
        Exit
    EndFunc ;==>_Quit

    Func winFFInv()
; Activate/Set focus to FF Inventory Management Window
        WinActivate("Inventory Management - \\Remote", "")
; Wait for FF Inventory Management Window to become active
        WinWaitActive("Inventory Management - \\Remote")
    EndFunc ;==>winFFInv

    Func winExcelListFF()
;Activate/Set Focus to Excel Worksheet: Equip_List_FF.xls
        WinActivate("Microsoft Excel - Equip_List_FF.xls", "")
;Wait for Excel Worksheet: Equip_List_FF.xls to become active
        WinWaitActive("Microsoft Excel - Equip_List_FF.xls", "")
    EndFunc ;==>winExcelListFF

    Func winDataInserter()
; Activate/Set focus to FF Inventory Management Window
        WinActivate("Data AppInserter", "")
; Wait for Data AppInserter to become active
        WinWaitActive("Data AppInserter")
    EndFunc ;==>winDataInserter

    Func _ContExt($fPath1, $fpath3)
        Local $ContID, $ExitID, $msg

        GUICreate("Continue or Exit", 210, 80)

        GUICtrlCreateLabel("Continue with another worksheet or Exit!", 10, 10)
        $ContID = GUICtrlCreateButton("Continue", 90, 50, 55, 20)
        $ExitID = GUICtrlCreateButton("Exit", 150, 50, 55, 20)

        GUISetState(); display the GUI
        WinSetOnTop("Continue or Exit", "", 1);window stays on top

        Do
            $msg = GUIGetMsg()
            Select
                Case $msg = $ContID
            ; Run/Open FF Signin Webpage
                    ShellExecute($fPath1 & $fpath3)
                    Exit
                Case $msg = $ExitID
                    Exit
                Case $msg = $GUI_EVENT_CLOSE
                    Exit
            EndSelect
        Until $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID
    EndFunc ;==>_ContExt

; #FUNCTION# ====================================================================================================


================
; Name...........: _ExcelBookAttach
; Description ...: Attach to the first existing instance of Microsoft Excel where the search string matches based on the selected mode.
; Syntax.........: _ExcelBookAttach($s_string, $s_mode = "FilePath")
; Parameters ....: $s_string - String to search for
;                 $s_mode   - Optional: specifies search mode:
;                 |FileName - Name of the open workbook
;                 |FilePath - (Default) Full path to the open workbook
;                 |Title    - Title of the Excel window
; Return values .: Success   - Returns an object variable pointing to the Excel.Application, workbook object
;                 Failure   - Returns 0 and sets @ERROR = 1
; Author ........: Bob Anthony (big_daddy)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
; ====================================================================================================


===========================
    Func _ExcelBookAttach($s_string, $s_mode = "FilePath")

        Local $o_Result, $o_workbook, $o_workbooks

        If $s_mode = "filepath" Then
            $o_Result = ObjGet($s_string)
            If Not @error And IsObj($o_Result) Then
                Return $o_Result
            EndIf
        EndIf

        $o_Result = ObjGet("", "Excel.Application")
        If @error Or Not IsObj($o_Result) Then
            ConsoleWrite("--> Warning from function _ExcelAttach, No existing Excel.Application object" & @CR)
            Return SetError(1, 0, 0)
        EndIf

        $o_workbooks = $o_Result.Application.Workbooks
        If Not IsObj($o_workbooks) Or $o_workbooks.Count = 0 Then
            ConsoleWrite("--> Warning from function _ExcelAttach, No existing Excel.Application windows" & @CR)
            Return SetError(1, 0, 0)
        EndIf

        For $o_workbook In $o_workbooks

            Switch $s_mode
                Case "filename"
                    If $o_workbook.Name = $s_string Then
                        Return $o_workbook
                    EndIf
                Case "filepath"
                    If $o_workbook.FullName = $s_string Then
                        Return $o_workbook
                    EndIf
                Case "title"
                    If ($o_workbook.Application.Caption) = $s_string Then
                        Return $o_workbook
                    EndIf
                Case Else
                    ConsoleWrite("--> Error from function _ExcelAttach, Invalid Mode Specified" & @CR)
                    Return SetError(1, 0, 0)
            EndSwitch
        Next

        ConsoleWrite("--> Warning from function _ExcelAttach, No Match" & @CR)
        Return SetError(1, 0, 0)
    EndFunc ;==>_ExcelBookAttach

;===============================================================================
;
; Description:    Closes the active workbook and removes the specified Excel object.
; Syntax:          _ExcelBookClose($oExcel, $fSave = 1, $fAlerts = 0)
; Parameter(s):  $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
;              $fSave - Flag for saving the file before closing (0=no save, 1=save) (default = 1)
;              $fAlerts - Flag for disabling/enabling Excel message alerts (0=disable, 1=enable) (default = 0)
; Requirement(s):   None
; Return Value(s):  On Success - Returns 1
;                  On Failure - Returns 0 and sets @error on errors:
;                 @error=1 - Specified object does not exist
;                 @error=2 - File exists, overwrite flag not set
; Author(s):        SEO <locodarwin at yahoo dot com>
; Note(s):        None
;
;===============================================================================
    Func _ExcelBookClose1($oExcel, $fSave = 1, $fAlerts = 0)
        If Not IsObj($oExcel) Then Return SetError(1, 0, 0)
        $sObjName = ObjName($oExcel)

        If $fSave > 1 Then $fSave = 1
        If $fSave < 0 Then $fSave = 0
        If $fAlerts > 1 Then $fAlerts = 1
        If $fAlerts < 0 Then $fAlerts = 0

; Save the users specified settings
        $fDisplayAlerts = $oExcel.Application.DisplayAlerts
        $fScreenUpdating = $oExcel.Application.ScreenUpdating
; Make necessary changes
        $oExcel.Application.DisplayAlerts = $fAlerts
        $oExcel.Application.ScreenUpdating = $fAlerts

        If $fSave Then
            $oExcel.ActiveWorkBook.Save
        EndIf

; Restore the users specified settings
        $oExcel.Application.DisplayAlerts = $fDisplayAlerts
        $oExcel.Application.ScreenUpdating = $fScreenUpdating

        Switch $sObjName
            Case "_Workbook"
        ; Check if multiple workbooks are open
        ; Do not close application if there are
                If $oExcel.Application.Workbooks.Count > 1 Then
                    $oExcel.Close
                Else
                    $oExcel.Application.Quit
                EndIf
            Case "_Application"
                $oExcel.Quit
            Case Else
                Return SetError(1, 0, 0)
        EndSwitch

        Return 1
    EndFunc ;==>_ExcelBookClose1

Thank you for your help,

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

What are you making changes to? The information contained in variables? The source code? You still need to be more specific.

When the part of the script is running below if some data is entered wrong or not selected then instead of waiting for the script to continue running I would like to stop the script but not exit then make the corrections then continue running the script.

Do
                            $msg3 = GUIGetMsg()
                            Select
                                Case $msg3 = $GUI_EVENT_CLOSE
                                    Exit
                                Case $msg3 = $btn_Next Or $msg3 = $btn_Previous
                                    If $msg3 = $btn_Previous Then
                                        $i = $i - 2
                                        _GUICtrlButton_Enable($btn_Previous, False);Disables Previous Button
                                    Else
                                    ;Call Function to Activate/maximize FF Inventory Management - \\Remote window
                                        winFFInv()
                                    ;Click Insert
                                    ; Click in FF Equipment Field
                                        MouseClick("left", 114, 135)
                                    ; Now that the Notepad window is active type some special characters
                                        Send($sCellValue3 & "{ENTER}");invpart & Equipment
                                        Sleep(2000)
                                        Send($sCellValue1 & "-" & $sCellValue2 & "{ENTER 2}");serialno
                                        Sleep(2000)
                                        Send($sCellValue4 & "{ENTER 2}");description
                                        Sleep(2000)
                                        Send("U" & "{ENTER 7}");status
                                        Sleep(2000)
                                        Send("16" & "{ENTER 4}");shop
                                        Sleep(2000)
                                        Send($sCellValue1 & "{ENTER}");bldgno
                                        ;Closes Property Notes - \\Remote if opens
                                            Sleep(1000)                                     
                                            If WinExists("Property Notes - \\Remote") Then 
                                                WinActivate("Property Notes - \\Remote", "")
                                                Send("!C")
                                            EndIf
                                        
                                            Sleep(2000)
                                            Send($sCellValue6);loc

                                            If $sCellValue7 > "" Then
                                                Sleep(2000)
                                            ; Click the Extra Description Box
                                                MouseClick("left", 516, 210)
                                            ;Extra Description Box Text
                                                Send($sCellValue7)
                                                Sleep(2000)
                                                Send("!C{ENTER}")

                                                _GUICtrlButton_Enable($btn_Previous);Disables Previous Button
                                            EndIf
                                        EndIf
                                EndSelect
                            Until $msg3 = $btn_Next Or $msg3 = $btn_Previous

Thenk you for your help,

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

...

You just repeated the same thing. What are you correcting? The data in variables? The data in whatever you are trying to automate? Gosh, I can't help you if you don't tell me anything.

Thank for your help Richard Robertson, I'm doing the best I know how. I do not understand what you are asking for because I'm not trying to correct the data in variables or anything else. The script works but I'm trying to add to the code as stated in my previous post.

Now you are getting rude and impolite so I'm asking you please do not reply to this post allow somone else to help me and if I do not get any other replies then I will have to figure it out myself.

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

I have your Answer mate !

Example Function, With Example Hotkey

Lets say you had a Function called Main()

Global $running

HotKeySet("{PAUSE}", "Main")

Func Main()

$running = NOT $running

While $running

<Do Events Here>

Wend

End Func

Simply Pressing your hotkey "Pause" in this example would Start AND Stop the function without exiting the Program.

Let's use your piece now for example.

Remeber to Declare Global $running, or Local $running either should work. Well it don't have to be $running exactly lol
it can be whatever you wish to make it ..you get it XD

Func <Func Here>

$running = NOT $running

While $running
                            $msg3 = GUIGetMsg()
                            Select
                                Case $msg3 = $GUI_EVENT_CLOSE
                                    Exit
                                Case $msg3 = $btn_Next Or $msg3 = $btn_Previous
                                    If $msg3 = $btn_Previous Then
                                        $i = $i - 2
                                        _GUICtrlButton_Enable($btn_Previous, False);Disables Previous Button
                                    Else
                                  ;Call Function to Activate/maximize FF Inventory Management - \\Remote window
                                        winFFInv()
                                  ;Click Insert
                                  ; Click in FF Equipment Field
                                        MouseClick("left", 114, 135)
                                  ; Now that the Notepad window is active type some special characters
                                        Send($sCellValue3 & "{ENTER}");invpart & Equipment
                                        Sleep(2000)
                                        Send($sCellValue1 & "-" & $sCellValue2 & "{ENTER 2}");serialno
                                        Sleep(2000)
                                        Send($sCellValue4 & "{ENTER 2}");description
                                        Sleep(2000)
                                        Send("U" & "{ENTER 7}");status
                                        Sleep(2000)
                                        Send("16" & "{ENTER 4}");shop
                                        Sleep(2000)
                                        Send($sCellValue1 & "{ENTER}");bldgno
                                      ;Closes Property Notes - \\Remote if opens
                                            Sleep(1000)                                     
                                            If WinExists("Property Notes - \\Remote") Then
                                                WinActivate("Property Notes - \\Remote", "")
                                                Send("!C")
                                            EndIf
                                        
                                            Sleep(2000)
                                            Send($sCellValue6);loc

                                            If $sCellValue7 > "" Then
                                                Sleep(2000)
                                          ; Click the Extra Description Box
                                                MouseClick("left", 516, 210)
                                          ;Extra Description Box Text
                                                Send($sCellValue7)
                                                Sleep(2000)
                                                Send("!C{ENTER}")

                                                _GUICtrlButton_Enable($btn_Previous);Disables Previous Button
                                            EndIf
                                        EndIf
                                EndSelect
                           Wend
EndFunc
Edited by blinko2008
Link to comment
Share on other sites

Did you just say you want to make corrections to the code? That's what I was asking from the beginning. You can't make changes while the script is running.

I was being rude because I was frustrated. I cannot help if you do not describe a problem.

I think he means that he wants to correct changes made by the script in a different program ( like Excel ), things that the script did wrong and he wants to correct.

Link to comment
Share on other sites

Richard Robertson,

Did you just say you want to make corrections to the code? That's what I was asking from the beginning. You can't make changes while the script is running.

No, I'm not trying to make corrections to my code!

I was being rude because I was frustrated. I cannot help if you do not describe a problem.

No, I do not have a problem with my code to describe!

So you aren't really sure either? I've just been guessing here.

Yes, I do know what I want. But, I do not know how to explain it so that you can understand what I want to do.

I apologize for my lack of knowledge coding in autoit3 and for getting you so frustrated. So, I'll continue to research this forum and the help file for answers.

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

I was asking nf67 if he/she understood what you were asking.

And you do have a problem with your code, jfcby. Otherwise you wouldn't be here asking for help, right? I'm sorry that I can't understand what you are asking. Don't apologize for not knowing AutoIt though. It's your written communication that is the problem. You don't appear to speak English as your first language and that is why I don't understand. Sorry I couldn't help.

Link to comment
Share on other sites

I have your Answer mate !

Example Function, With Example Hotkey

Lets say you had a Function called Main()

Global $running

HotKeySet("{PAUSE}", "Main")

Func Main()

$running = NOT $running

While $running

<Do Events Here>

Wend

End Func

Simply Pressing your hotkey "Pause" in this example would Start AND Stop the function without exiting the Program.

Let's use your piece now for example.

Remeber to Declare Global $running, or Local $running either should work. Well it don't have to be $running exactly lol
it can be whatever you wish to make it ..you get it XD

Func <Func Here>

$running = NOT $running

While $running
                            $msg3 = GUIGetMsg()
                            Select
                                Case $msg3 = $GUI_EVENT_CLOSE
                                    Exit
                                Case $msg3 = $btn_Next Or $msg3 = $btn_Previous
                                    If $msg3 = $btn_Previous Then
                                        $i = $i - 2
                                        _GUICtrlButton_Enable($btn_Previous, False);Disables Previous Button
                                    Else
                                 ;Call Function to Activate/maximize FF Inventory Management - \\Remote window
                                        winFFInv()
                                 ;Click Insert
                                 ; Click in FF Equipment Field
                                        MouseClick("left", 114, 135)
                                 ; Now that the Notepad window is active type some special characters
                                        Send($sCellValue3 & "{ENTER}");invpart & Equipment
                                        Sleep(2000)
                                        Send($sCellValue1 & "-" & $sCellValue2 & "{ENTER 2}");serialno
                                        Sleep(2000)
                                        Send($sCellValue4 & "{ENTER 2}");description
                                        Sleep(2000)
                                        Send("U" & "{ENTER 7}");status
                                        Sleep(2000)
                                        Send("16" & "{ENTER 4}");shop
                                        Sleep(2000)
                                        Send($sCellValue1 & "{ENTER}");bldgno
                                     ;Closes Property Notes - \\Remote if opens
                                            Sleep(1000)                                     
                                            If WinExists("Property Notes - \\Remote") Then
                                                WinActivate("Property Notes - \\Remote", "")
                                                Send("!C")
                                            EndIf
                                        
                                            Sleep(2000)
                                            Send($sCellValue6);loc

                                            If $sCellValue7 > "" Then
                                                Sleep(2000)
                                         ; Click the Extra Description Box
                                                MouseClick("left", 516, 210)
                                         ;Extra Description Box Text
                                                Send($sCellValue7)
                                                Sleep(2000)
                                                Send("!C{ENTER}")

                                                _GUICtrlButton_Enable($btn_Previous);Disables Previous Button
                                            EndIf
                                        EndIf
                                EndSelect
                           Wend
EndFunc
Hi vblinko2008,

This is close to what I need. The only problem is that it continues to run non stop.

This is some code I've been trying to modify form the help file to work the way I need it to:

Global _msg3btn

HotKeySet("{PAUSE}", "_msg3btn")

Func _msg3btn()     
        $Paused = NOT $Paused
        While $Paused
            sleep(100)
            ToolTip('Script is "Paused"',0,0)           
        WEnd
        ToolTip("")         
    EndFunc

This code when I continue begins at the same location in the script that it was at when paused.

In this portion of the script this is what I need it to do:

When this portion of the code is running and I click the Keyboard Pause button the script stops. But, when I restart the script instead of it continuing at the same location it paused in I need it to start at this location each time. Is this possible?

Dim $sCellValue1, $sCellValue2, $sCellValue3, $sCellValue4, $sCellValue6, $sCellValue7
                    Dim $msg3, $btn_Stop, $cnt
                ;Insert Next Part
                    _WinAPI_MoveWindow($GUI, $mpX, $mpY, $wwdth, $whght);moves window to upper right corener
                    WinSetOnTop("Data AppInserter", "", 1);window stays on top
                    GUICtrlCreateLabel("Insert Next Part", 100, 315, 125, 25)
                    $btn_Next = GUICtrlCreateButton("Next", 235, 315, 75, 25);Left, Down, Width, Height
                    GUICtrlCreateLabel("ReInsert Previous Part", 100, 350, 125, 25)
                    $btn_Previous = GUICtrlCreateButton("Previous", 235, 350, 75, 25)
                    $btn_Stop = GUICtrlCreateButton("Stop", 20, 350, 75, 25)
                ;MsgBox(0, "", "$nrowM = " & $nrowM & " - " & "$lrowM = " & $lrowM)
                ;MsgBox(0, "", "The Cell Value is: " &  @CRLF & $sCellValue1);& @CRLF & $sCellValue5 & @CRLF & $sCellValue6, )
                    $sCellValue1 = StringTrimLeft(_ExcelReadCell($oExcel1, 2, 3), 7);bldgno
                    For $i = $nrowM To $lrowM;Loop
                        $sCellValue2 = _ExcelReadCell($oExcel1, $i, 2);serialno
                        $sCellValue3 = _ExcelReadCell($oExcel1, $i, 3);ffinvpart & Equipment
                        $sCellValue4 = _ExcelReadCell($oExcel1, $i, 4);description
                        $sCellValue6 = _ExcelReadCell($oExcel1, $i, 6);roomno
                        $sCellValue7 = _ExcelReadCell($oExcel1, $i, 7);extradesc or notes
                        Do
                            $msg3 = GUIGetMsg()
                            Select
                                Case $msg3 = $GUI_EVENT_CLOSE
                                    Exit
                                Case $msg3 = $btn_Next Or $msg3 = $btn_Previous Or  $msg3 = $cnt
                                    If $msg3 = $btn_Previous Then
                                        $i = $i - 2
                                        _GUICtrlButton_Enable($btn_Previous, False);Disables Previous Button                                    
                                    Else;if $msg3 = $btn_Next Then
                                    ;Call Function to Activate/maximize FF Inventory Management - \\Remote window
                                        winFFInv()
                                    ;Click Insert
                                    ; Click in FF Equipment Field
                                        MouseClick("left", 114, 135)
                                    ; Now that the Notepad window is active type some special characters
                                        Send($sCellValue3 & "{ENTER}");invpart & Equipment
                                        Sleep(2000)
                                        Send($sCellValue1 & "-" & $sCellValue2 & "{ENTER 2}");serialno
                                        Sleep(2000)
                                        Send($sCellValue4 & "{ENTER 2}");description
                                        Sleep(2000)
                                        Send("U" & "{ENTER 7}");status
                                        Sleep(2000)
                                        Send("16" & "{ENTER 4}");shop
                                        Sleep(2000)
                                        Send($sCellValue1 & "{ENTER}");bldgno
                                        ;Closes Property Notes - \\Remote if opens
                                            Sleep(1000)                                     
                                            If WinExists("Property Notes - \\Remote") Then 
                                                WinActivate("Property Notes - \\Remote", "")
                                                Send("!C")
                                            EndIf
                                        
                                            Sleep(2000)
                                            Send($sCellValue6);loc

                                            If $sCellValue7 > "" Then
                                                Sleep(2000)
                                            ; Click the Extra Description Box
                                                MouseClick("left", 516, 210)
                                            ;Extra Description Box Text
                                                Send($sCellValue7)
                                                Sleep(2000)
                                                Send("!C{ENTER}")

                                                _GUICtrlButton_Enable($btn_Previous);Disables Previous Button
                                            EndIf
                                        EndIf
                                EndSelect
                            Until $msg3 = $btn_Next Or $msg3 = $btn_Previous
                        Next

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Richard Robertson,

I was asking nf67 if he/she understood what you were asking.

I apologize for the misunderstanding.

And you do have a problem with your code, jfcby. Otherwise you wouldn't be here asking for help, right?

Wrong, I do not have any problems with my posted code above. I'm having a difficult time understanding how to add some code to make the current code work better and more efficient saving time.

I'm sorry that I can't understand what you are asking. Don't apologize for not knowing AutoIt though. It's your written communication that is the problem. You don't appear to speak English as your first language and that is why I don't understand. Sorry I couldn't help.

English is the only language I speak. Not knowing enough about AutoIt does make it hard to put into words how I want to add to my working code. That is the reason my written communication is difficult to understand and why I do not understand what you are asking.

Thank you for your help,

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Hi,

Script Add-on almost complete but not exactly what I want but close.

Since my original post I gained some knowledge about I need and as other has stated it is "Pause". Now, through researching this forum and the help file I've been able to insert some code to use a "HotSetKey" to pause my script.

The way the "HotSetKey" works now, where it pauses the script it un-pauses it at the same location. I need to specify the location where to restart the script. It can be done by moving that portion of the script to a function and then add it to my pause function.

When using a "For To Next" statement how can the HowSetKey be used to always begin at specific location. The location is specified below.

$sCellValue1 = StringTrimLeft(_ExcelReadCell($oExcel1, 2, 3), 7);bldgno
                    For $i = $nrowM To $lrowM;Loop
                        $sCellValue2 = _ExcelReadCell($oExcel1, $i, 2);serialno
                        $sCellValue3 = _ExcelReadCell($oExcel1, $i, 3);ffinvpart & Equipment
                        $sCellValue4 = _ExcelReadCell($oExcel1, $i, 4);description
                        $sCellValue6 = _ExcelReadCell($oExcel1, $i, 6);roomno
                        $sCellValue7 = _ExcelReadCell($oExcel1, $i, 7);extradesc or notes

I need this portion in a function but when I put it in a function the for statement repeats inserting the same data when the "HotSetKey" Pause is used.

Do
                            $msg3 = GUIGetMsg()
                            Select
                                Case $msg3 = $GUI_EVENT_CLOSE
                                    Exit
                                Case $msg3 = $btn_Next Or $msg3 = $btn_Previous
                                    If $msg3 = $btn_Previous Then
                                        $i = $i - 2
                                        _GUICtrlButton_Enable($btn_Previous, False);Disables Previous Button                                    
                                    Else;if $msg3 = $btn_Next Then
                                    ;Call Function to Activate/maximize FF Inventory Management - \\Remote window
                                        winFFInv()
                                        Sleep(500)
                                    ;Click Insert
                                        Send("{F4}")
                                    ; Click in FF Equipment Field
                                        MouseClick("left", 114, 135)
                                    ; Now that the Notepad window is active type some special characters
                                        Send($sCellValue3 & "{ENTER}");invpart & Equipment
                                        Sleep(2000)
                                        Send($sCellValue1 & "-" & $sCellValue2 & "{ENTER 2}");serialno
                                        Sleep(2000)
                                        Send($sCellValue4 & "{ENTER 2}");description
                                        Sleep(2000)
                                        Send("U" & "{ENTER 7}");status
                                        Sleep(2000)
                                        Send("16" & "{ENTER 4}");shop
                                        Sleep(2000)
                                        Send($sCellValue1 & "{ENTER}");bldgno
                                        ;Closes Property Notes - \\Remote if opens
                                            Sleep(1000)                                     
                                            If WinExists("Property Notes - \\Remote") Then 
                                                WinActivate("Property Notes - \\Remote", "")
                                                Send("!C")
                                            EndIf
                                        
                                            Sleep(2000)
                                            Send($sCellValue6);loc

                                            If $sCellValue7 > "" Then
                                                Sleep(2000)
                                            ; Click the Extra Description Box
                                                MouseClick("left", 516, 210)
                                            ;Extra Description Box Text
                                                Send($sCellValue7)
                                                Sleep(2000)
                                                Send("!C{ENTER}")

                                                _GUICtrlButton_Enable($btn_Previous);Disables Previous Button
                                            EndIf
                                        EndIf
                                EndSelect
                            Until $msg3 = $btn_Next Or $msg3 = $btn_Previous

End portion needed in a function.

Next

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...