Jump to content

Do..Until issues - pausing and continue


DougH
 Share

Recommended Posts

Good day all,

I am working on a script that scans drectories in a Network Share for a specific file containing SQL statement and processes the statement into the databse. I have this part working great. I have three buttons on the form, Pause, Continue, Exit. The loop I am using is a Do ... Until it finds a file. What I would like to do is pause the loop, continue the loop or exit the script. I am having difficulty making this work. I have tried AdLibEnable but I cannot get it to work. The code for the loop is included below. Any idea how I can make this work?

Func ScanDir($ShareDir)

$Srvr = Ping($ServerIP,250)

If Not $Srvr then

RunWait("Rasdial.exe NMSC nmsc\Facility_Backup Nutrition","", @SW_HIDE);Connects to the specified dial-up entry

Else

DriveMapAdd("J:", $ShareDir, 0, $UserName, $Pass)

If @Error <> "0" And @Error <> "3" Then

MsgBox(0, "Drive Mapping", "Mapping Error - " & @Error)

EMailError($Msg2)

Endif

EndIf

$ScanDir = _FileListToArray ( $ShareDir, "*", 2)

;Scan Directories for a Folder called Input which contain inbx[0000].sql files.

Do

For $D = 1 to $ScanDir[0] Step 1

If FileExists($ShareDir & "\" & $ScanDir[$D] & "\input\inbx*.sql") Then

$DirFile = _FileListToArray ($ShareDir & "\" & $ScanDir[$D] & "\input\", "inbx*.sql", 1)

For $F = 1 to $DirFile[0] step 1

$File = GUICtrlRead(FileExists($ShareDir & "\" & $ScanDir[$D] & "\input\" & $DirFile[$F]))

GUICtrlSetData($ParseList, "Located File " & $ShareDir & "\" & $ScanDir[$D] & "\input\" & $DirFile[$F])

ProcessSQL($ScanDir[$D], "", $ShareDir & "\" & $ScanDir[$D] & "\input\" & $DirFile[$F])

Next

Else

GUICtrlSetData($ParseList, "Scanning Directory " & $ScanDir[$D])

sleep(300)

EndIf

Next

Until $File

EndFunc

Thank you in advance

Link to comment
Share on other sites

One of many techniques:

Global $fPause = False

; ...create GUI with GuiOnEventMode = 1
; GuiCtrlCreateButton("Pause", ...)
; GuiCtrlSetOnEvent(-1, "_PauseButton")
; GuiCtrlCreateButton("Continue", ...)
; GuiCtrlSetOnEvent(-1, "_ContinueButton")
; GuiCtrlCreateButton("Exit", ...)
; GuiCtrlSetOnEvent(-1, "_ExitButton")

Func ScanDir($ShareDir)
    $Srvr = Ping($ServerIP, 250)
    If Not $Srvr Then
        RunWait("Rasdial.exe NMSC nmsc\Facility_Backup Nutrition", "", @SW_HIDE);Connects to the specified dial-up entry
    Else
        DriveMapAdd("J:", $ShareDir, 0, $UserName, $Pass)
        If @error <> "0" And @error <> "3" Then
            MsgBox(0, "Drive Mapping", "Mapping Error - " & @error)
            EMailError($Msg2)
        EndIf
    EndIf
    $ScanDir = _FileListToArray($ShareDir, "*", 2)
    ;Scan Directories for a Folder called Input which contain inbx[0000].sql files.
    Do
        For $D = 1 To $ScanDir[0] Step 1
            While $fPause
                Sleep(20)
            WEnd
            If FileExists($ShareDir & "\" & $ScanDir[$D] & "\input\inbx*.sql") Then
                $DirFile = _FileListToArray($ShareDir & "\" & $ScanDir[$D] & "\input\", "inbx*.sql", 1)
                For $F = 1 To $DirFile[0] Step 1
                    While $fPause
                        Sleep(20)
                    WEnd
                    $File = GUICtrlRead(FileExists($ShareDir & "\" & $ScanDir[$D] & "\input\" & $DirFile[$F]))
                    GUICtrlSetData($ParseList, "Located File " & $ShareDir & "\" & $ScanDir[$D] & "\input\" & $DirFile[$F])
                    ProcessSQL($ScanDir[$D], "", $ShareDir & "\" & $ScanDir[$D] & "\input\" & $DirFile[$F])
                Next
            Else
                GUICtrlSetData($ParseList, "Scanning Directory " & $ScanDir[$D])
                Sleep(300)
            EndIf
        Next
    Until $File
EndFunc   ;==>ScanDir

Func _PauseButton()
    $fPause = True
EndFunc   ;==>_PauseButton

Func _ContinueButton()
    $fPause = False
EndFunc   ;==>_ContinueButton

Func _ExitButton()
    Exit
EndFunc

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...