Jump to content
Sign in to follow this  
johnjam

Program stop

Recommended Posts

johnjam

Hello to all,

I've taken Zedna's advice and got my self stuck into the IE UDF's and they work just great for me however, I've bumped into a problem that I can't seem to get to the bottom of. My program aquires images and for the most part works pretty good until i reach around 500 ojects downloaded to a directory. The last count was 487 Images and before that 503 images, been on this for about a week now. I am hoping that some one can shed some light as to why the program stops getting images around this Number, the program continues to process without error however, the image count does not increase.

Many Thanks in advance.

Opt("WinTitleMatchMode", 2)
Opt("CaretCoordMode", 0)
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client
Opt("PixelCoordMode", 1) ;1=absolute, 0=relative, 2=client

#include <GUIConstants.au3>
#include <File.au3>
#include <IE.au3>
#include <Inet.au3>
;#include <imagesearch.au3>
#include <Array.au3>
#include <String.au3>

Dim $oMyError
Dim $oIE_Popup
Dim $sMyString = "View Illustration"
Dim $oIMGs
Dim $sImgUrl
Dim $sImgDir = "C:\IMG\Images\Thumbs\"
Dim $sImgDir1 = "C:\IMG\Images\P1's\"; These will be a mixture of gif and jpg
Dim $sImgDir2 = "C:\IMG\Images\Diagrams\"
Dim $oIE1
Dim $sloc
Dim $body
Dim $Find
Dim $Findx
Dim $csvArray
Dim $Errx = "C:\Dir\IEBody.txt"
Dim $x
Dim $element
Dim $oIE
Dim $5dig = "00000"
Dim $4dig = "0000"
Dim $3dig = "000"
Dim $2dig = "00"
Dim $1dig = "0"
Global $sLogPath = "C:\Dir\Notfound.txt"
Global $sStatus = ""
Global $sLogMsg = ""
Global $Paused
Global $oImg
;$__IEAU3Debug = True
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Initialize a COM error handler
Global $oMyError = ObjEvent("AutoIt.Error", "errHandler")

DirCreate("C:\IMG\Images\P1's\")

MsgBox(0, "Image Save Location", "Images will be saved in C:\IMG", 1)

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{HOME}", "ShowMessage") ;Shift-Alt-d

$oIE = _IECreate("http://www.Domain.co.uk")
WinSetState("Internet Explorer", "", @SW_MAXIMIZE)
SplashTextOn("First interiors", "First interiors" & @CRLF & "Initialising Programme...", 250, 150, 30, 30, 1, "", 12)
SplashTextOn("First interiors", "First interiors" & @CRLF & "Mouse move to start position", 250, 150, 30, 30, 1, "", 12)
If Not _FileReadToArray("C:\JB1\B.csv", $csvArray) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf

For $x = 1 To $csvArray[0]
    If StringLen($csvArray[$x]) = 4 Then
        $Line = $4dig
    ElseIf StringLen($csvArray[$x]) = 5 Then
        $Line = $3dig
    ElseIf StringLen($csvArray[$x]) = 6 Then
        $Line = $2dig
    ElseIf StringLen($csvArray[$x]) = 7 Then
        $Line = $1dig
    ElseIf StringLen($csvArray[$x]) = 8 Then
        $Line = ""
    ElseIf StringLen($csvArray[$x]) = 9 Then
        $Line = ""
    EndIf
    Sleep(100)
    If FileExists($Errx) Then
        $FileHandle = FileOpen($Errx, 2); Mode 2 used to clear contents of body read
        FileClose($FileHandle)
    EndIf
    Sleep(100)

    _IELoadWait($oIE)

    Sleep(2000)
    $oForm = _IEFormGetObjByName($oIE, "quicksearch");name of the form in question
    $oText = _IEFormElementGetObjByName($oForm, "searchtext");name of the textbox search using DebugBar
    _IEFormElementSetValue($oText, $Line & $csvArray[$x])
    _IEFormSubmit($oForm)
    Sleep(1000)
    _IELoadWait($oIE)
    Sleep(1000)
    $Findx = "And Microsoft OLE DB Provider for ODBC Drivers error";
    $Find = "Sorry. No Matches Found for -"
    Sleep(100)
    $body = _IEBodyReadHTML($oIE)
    $sloc = @ScriptDir & "\IEBody.txt"
    Sleep(1000)
    FileWrite($sloc, $body)
    $sfile = FileOpen($sloc, 0)
    $num = 0
    While 1
        $num = $num + 1
        $sline = FileReadLine($sfile, $num)
        If @error Then
            Sleep(1000)
            Call("AquireImage")
            ExitLoop
        EndIf
        If StringInStr($sline, $Find) Then
            MsgBox(4096, "NO IMAGE", "No Image for " & $csvArray[$x] & " was found " & @CRLF & " on Site ", 1)
            Sleep(1000)
            Call("Err")
            ExitLoop
        EndIf
        If StringInStr($sline, $Findx) Then
            MsgBox(4096, "NO IMAGE", "No Image for " & $csvArray[$x] & " was found " & @CRLF & " on Site ", 1)
            Sleep(1000)
            Call("Err")
            ExitLoop
        EndIf
    WEnd
Next

Func AquireImage()
    _IEImgClick($oIE, "but-arrow-more.gif", "src")
    _IELoadWait($oIE)
    SplashTextOn("Aquire PIC", "Aquire PIC P1 Coding." & @CRLF & $csvArray[$x], 250, 150, 30, 30, 1, "", 12)
    $oImg = _IEImgGetCollection($oIE, 2)
    _IEErrorHandlerRegister("MyErrFunc")
    If IsObj($oImg) Then
        $sImgUrl = $oImg.src
        $sImgFileName = $oImg.nameProp
        InetGet($sImgUrl, $sImgDir1 & "Img_" & $csvArray[$x] & "P1" & ".jpeg", 0, 0)
    EndIf
    Sleep(100)
    Return
EndFunc   ;==>AquireImage

Func Err()
    Sleep(1000)
    $sLogMsg = $csvArray[$x]
    SplashTextOn("Error Log", "Writing to Error Log." & @CRLF & $csvArray[$x], 250, 150, 30, 30, 1, "", 12)
    Sleep(1000)
    FileOpen($sLogPath, 1)
    _FileWriteLog($sLogPath, $sLogMsg, -1)
    FileClose($sLogPath)
    SplashTextOn("Error Log", "Error Log Complete." & @CRLF & $csvArray[$x], 250, 150, 30, 30, 1, "", 12)
    Return
    SplashOff()
    Return
EndFunc   ;==>Err

Func MyErrFunc()
    ; Important: the error object variable MUST be named $oIEErrorHandler
    $ErrorScriptline = $oIEErrorHandler.scriptline
    $ErrorNumber = $oIEErrorHandler.number
    $ErrorNumberHex = Hex($oIEErrorHandler.number, 8)
    $ErrorDescription = StringStripWS($oIEErrorHandler.description, 2)
    $ErrorWinDescription = StringStripWS($oIEErrorHandler.WinDescription, 2)
    $ErrorSource = $oIEErrorHandler.Source
    $ErrorHelpFile = $oIEErrorHandler.HelpFile
    $ErrorHelpContext = $oIEErrorHandler.HelpContext
    $ErrorLastDllError = $oIEErrorHandler.LastDllError
    $ErrorOutput = ""
    $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR
    $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR
    $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR
    $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR
    $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR
    $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR
    $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR
    $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR
    $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR
    $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError
    MsgBox(0, "COM Error", $ErrorOutput, 1)
    SetError(1)
    Return
EndFunc   ;==>MyErrFunc

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func ShowMessage()
    MsgBox(4096, "Programming", "AUTO IT :Programming")
EndFunc   ;==>ShowMessage
Exit
Edited by johnjam

Regards JohnJam

Share this post


Link to post
Share on other sites
Melba23

johnjam,

Firstly, if you post code, please use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). :)

As to your problem, anything that stops around 500 always makes me think of unclosed file handles - you can only have 512 at any one time. And sure enough, you have this line in a loop:

$sfile = FileOpen($sloc, 0)
with no corresponding FileCLose line.

Over to you!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
johnjam

Hi M23,

First of all many thanks for the quick response.

I did not not Know about the auto it tags but will do in future

I'll give your suggestion a try and see how I get on


Regards JohnJam

Share this post


Link to post
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
Sign in to follow this  

×