Jump to content

Gui On Event Mode - Events queued until script told to exit


 Share

Recommended Posts

Hey everybody.

I have been using GUIOnEventMode for a while now, and have never come across this problem. When I am running my script, if I click a button with an event assigned to it, then it seems to queue the events until I right click on the autoit tray icon and tell it to exit, and then it runs the appropriate events for the functions, and then continues to run the script until it reaches the next GUI, and then the same happens. This is the script (Ofcourse I have removed the company name from it though). I am using 3.3.8.0 on Windows 7 Home Premium 64 bit, running the 32 bit AutoIT Executable.

#AutoIt3Wrapper_UseX64=N
#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <Misc.au3>
#include <String.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnEsc", 0)
Opt("TrayAutoPause", 0)
_GDIPlus_Startup()
OnAutoItExitRegister('_OnExit')
Global $TestGui = 0, $DataGuiArray[10], $ProdNumGuiArray[6], $GUIArray[19], $Selected, $FilePath, $File, $Product, $PInfo, $PWarranty, $PDetails, $PCode, $PWrap, $PMain, $PName, $PCost, $PImages, $ImagesString, $Repeat, $PDetails, $PBrand, $PDelivery, $PWholeSale, $PSearchTags, $PWholesale, $SEOKeywords, $SEODesc, $PNum = "NO PRODUCT NUMBER", $PNumLimit, $MichaelBot = "MichaelBot/1.0 (+http://http://www.Michaelonline.com.au/)", $ThisImage = 0, $Pic, $ImagesGuiArray[5], $ImagesDirectory = "C:\Users\"&@UserName&"\Desktop\Images", $PImagesArray
Global $UsePNum = 0, $Mode = 0
HttpSetUserAgent($MichaelBot)
If $TestGui = 1 Then
    _CreateGUI()
EndIf
If $UsePNum = 1 Then
    _ProdNum()
EndIf
_Start()
Func _ProdNum()
    $ProdNumGuiArray[0] = GUICreate("Automatic Product Numbers", 120, 120)
    $ProdNumGuiArray[1] = GUICtrlCreateLabel("From", 20, 20, 30, 21)
    $ProdNumGuiArray[2] = GUICtrlCreateInput("", 50, 17, 50, 21)
    $ProdNumGuiArray[3] = GUICtrlCreateLabel("To", 20, 50, 21)
    $ProdNumGuiArray[4] = GUICtrlCreateInput("", 50, 47, 50, 21)
    $ProdNumGuiArray[5] = GUICtrlCreateButton("OK", 40, 80, 40, 30)
    GUICtrlSetOnEvent($ProdNumGuiArray[5], "_CheckProdNum")
    GUISetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $ProdNumGuiArray[0])
    Local $Msg = 0
    While 1
    WEnd
EndFunc
Func _CheckProdNum()
    GUISetState(@SW_HIDE, $ProdNumGuiArray[0])
    If GUICtrlRead($ProdNumGuiArray[2]) = "" Or GUICtrlRead($ProdNumGuiArray[4]) = "" Then
        MsgBox(0,"","Please insert a number in both input boxes.")
    Else
        If Number(GUICtrlRead($ProdNumGuiArray[2])) > Number(GUICtrlRead($ProdNumGuiArray[4])) Then
            MsgBox(0,"","The first number should be smaller than the second.")
        Else
            $PNum = Number(GUICtrlRead($ProdNumGuiArray[2]))
            $PNum -= 1
            $PNumLimit = Number(GUICtrlRead($ProdNumGuiArray[4]))
            GUIDelete($ProdNumGuiArray[0])
            _Start()
        EndIf
    EndIf
EndFunc
Func _Start()
    If $UsePNum = 1 Then
        If $PNum <> "NO PRODUCT NUMBER" Then
            If $PNum > $PNumLimit Then
                _ProdNum()
            Else
                $PNum += 1
            EndIf
        EndIf
    EndIf
    Local $URL = 'http://www.oo.com.au/Vivitar-iTwist-X018-Digital-Ca_P42902C901.cfm';InputBox("URL", "Please input the product's URL.", ClipGet())
    If $URL = "" Then
        MsgBox(0,"","No URL Supplied.")
        _Start()
    EndIf
    If Not _IsURL($URL) Then
        MsgBox(0,"","Given string is not URL.")
        _Start()
    EndIf
    If StringInStr($URL, "?") Then
        $URL = StringLeft($URL, StringInStr($URL, "?"))
    EndIf
    If Not StringInStr($URL, "http://") Then
        $URL = 'http://'&$URL
    EndIf
    Local $FilePath = @ScriptDir&"\File\File.html"
;~     ABOVE IS VALIDATION FOR THE URL
    ClipPut("")
;~     DOWNLOADING THE WEBPAGE
    InetGet($URL, $FilePath, 16, 0)
    If FileExists(@ScriptDir&"\File\File.htm") Then
        FileMove(@ScriptDir&"\File\File.htm", $FilePath, 9)
    EndIf
;~     ENSURING THAT THE CORRECT FILE EXISTS
    $File=FileRead($FilePath)
;~     GETTING THE FILE CONTENTS
    If $File = '' Then
;~         IF FILE NOT DOWNLOADED FROM OO ATTEMPT DOWNLOAD FROM GOOGLE CACHE
        MsgBox(0,"Error","Could Not Download from OO.com.au"&@CRLF&"Now attempting download from Google Cache.")
        If StringInStr($URL, 'http://') Then
;~             REMOVE HTTP FROM URL
            $URL = StringTrimLeft($URL, 7)
        EndIf
        $URL = StringTrimRight($URL, 9)&".cfm"
;~         REMOVE ARGUMENTS AND PARAMETERS FROM URL
        HttpSetUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1')
;~         SET USER AGENT TO FIREFOX TO AVOID GOOGLE CACHE ERRORS
        InetGet('http://webcache.googleusercontent.com/search?q=cache:'&$URL, $FilePath, 16, 0)
;~         ATTEMPT TO DOWNLOAD FILE FROM GOOGLE CACHE
        If FileExists(@ScriptDir&"\File\File.htm") Then
            FileMove(@ScriptDir&"\File\File.htm", $FilePath, 9)
        EndIf
;~         ENSURING THAT THE CORRECT FILE EXISTS
        HttpSetUserAgent($MichaelBot)
;~         RESETTING THE USER AGENT TO MichaelBOT
        $File=FileRead($FilePath)
;~         GETTING THE FILE CONTENTS
        If $File = '' Then
;~             IF FILE NOT DOWNLOADED FROM GOOGLE CACHE THEN DOWNLOAD MANUALLY
            MsgBox(0,"Error","Could Not Download from Google Cache"&@CRLF&"Please save the file manually to "&$FilePath&".")
            While Not FileExists($FilePath)
                If FileExists(@ScriptDir&"\File\File.htm") Then
                    FileMove(@ScriptDir&"\File\File.htm", $FilePath, 9)
                EndIf
;~                 ENSURING THAT THE CORRECT FILE EXISTS
                Sleep(1000)
            WEnd
;~             WAITING FOR USER TO DOWNLOAD FILE
            MsgBox(0,"","File detected. Attempting to use file as source.")
            $File=FileRead($FilePath)
;~             GETTING THE FILE CONTENTS
            If StringInStr(StringStripWS($File, 8), "Ashardaswetrywestillaren'tperfect.Wesuggestthatyoutryagainorcontactus.We'resorryforanyinconveniencethismaycause.We'lltryourbesttomakesureitdoesnothappenagain.") Then
                MsgBox(0,"ERROR","It appears that OO.com.au is down!"&@CRLF&"Attempting alternate download methods.")
            EndIf
            If $File = '' Or StringInStr(StringStripWS($File, 8), "Ashardaswetrywestillaren'tperfect.Wesuggestthatyoutryagainorcontactus.We'resorryforanyinconveniencethismaycause.We'lltryourbesttomakesureitdoesnothappenagain.") Then
;~                 IF OO IS OFFLINE OR IF USER COULD NOT DOWNLOAD FROM OO
                $Msgbox = MsgBox(4,"Error", "Program could not read contents of file."&@CRLF&"Would you like to attempt to manually load the file's HTML into the program?")
;~                 PRESENT USER WITH THE OPTION TO PASTE THE HTML INTO THE PROGRAM
                If $Msgbox = 6 Then
;~                     IF USER ACCEPTS
                    $File = InputBox("Insert HTML", "Please insert the page's source.", "")
;~                     PRESENT USER WITH AN INPUT BOX TO PASTE THE HTML
                    If $File = '' Then
;~                         IF THE USER PASTED NOTHING
                        MsgBox(0,"","Failed to retrieve page source from input box."&@CRLF&"Now Exiting.")
                        Exit
;~                         GIVE UP ON THE USER. MIGHT BE A GOOD IDEA TO BE PERSISTENT AND PLACE IN WHILE LOOP-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                    EndIf
                Else
;~                     IF USER DECLINES
                    MsgBox(0,"","As the program could not retrieve the requested data, it will not exit.")
                    Exit
;~                     EXIT
                EndIf
            EndIf
        EndIf
    EndIf
    If StringInStr($File, 'images/refurbished.gif') Then
;~         ENSURE THAT THE PRODUCT IS NOT REFURBISHED
        MsgBox(0,"REFURBISHED", "Error - This product has been refurbished!");http://www.oo.com.au/Kodak-M531-Digital-Camera-14_P89056C901.cfm
;~         FileDelete($File)
        _Start()
;~         IF THE PRODUCT IS REFURBISHED, THEN MOVE USER ON TO NEXT PRODUCT
    EndIf
;~    MsgBox(0,"",$File)
;~    FileDelete($FilePath)
    _GetData()
EndFunc
Func _GetData()
    $ThisImage = 0
    $Pic = 0
    $Product =                    _HTMLGetElementByID($File, 'product')
        $PInfo =                _HTMLGetElementByID($Product, 'p_info')
            $PWarranty =        _HTMLGetElementByID($PInfo, 'p_warranty')
                $PWarranty =    _HTMLGetWarranty($PWarranty)
            $PDetails =            _HTMLGetElementByID($PInfo, 'p_details')
                $PBrand =        _HTMLGetBrand($PDetails)
                If $PBrand = '' Then $PBrand = 'Michael'
                $PCode =        _HTMLGetProductCode($PDetails)
        $PWrap =                _HTMLGetElementByID($Product, 'p_wrap')
            $PMain =            _HTMLGetElementByID($PWrap, 'p_main')
                $PName =        StringTrimLeft(StringTrimRight($PMain, StringLen($PMain) - StringInStr($PMain, '</h1>')+1), StringInStr($PMain, '<h1>')+3)
                $PCost =        _HTMLGetCost($PMain)
                $PWholeSale = $PCost
                $PCost = _Price($PCost)
                $PDelivery =    _Delivery($PMain)
            $PImages =            _HTMLGetElementByID($PWrap, 'p_imgs')
                $PImages =        _HTMLGetImages($PImages)
                $PImagesArray =    StringSplit($PImages, "|", 3)
;~                 MsgBox(0,"",$PCode)
                For $Repeat = 0 To UBound($PImagesArray)-1
                    $PImagesArray[$Repeat] = 'http://img.oo.com.au/prod/'&$PCode&'/'&$Repeat+1&'b.jpg'
                Next
                $PDetails =        _HTMLGetDescription($PDetails, $PWarranty)
                $PSearchTags =    _GetSearchTags($PName)
                $SEOKeywords =    _GetSEOKeywords($PName)
                $SEODesc =        _GetSEODescription($PDetails)
                _Images()
EndFunc
Func _CreateGUI()
    ;GUI WINDOW
    $GUIArray[0] =        GUICreate("          ", 170, 580, @DesktopWidth-200, 75)
                        WinSetOnTop($GuiArray[0], "", 1)
    ;BASIC DETAILS
    $GUIArray[1] =        GUICtrlCreateRadio("Product Name", 22, 25)
    $GUIArray[2] =        GUICtrlCreateRadio("Product Code", 22, 45)
    ;PRICE DETAILS
    $GUIArray[3] =        GUICtrlCreateRadio("Final Price", 22, 90)
    ;DESCRIPTION
    $GUIArray[4] =        GUICtrlCreateRadio("Description", 22, 135)
    ;IMAGES
    $GUIArray[5] =        GUICtrlCreateRadio("Images", 22, 180) ;Copies the image URL into an array
    ;ADVANCED DETAILS
    $GUIArray[6] =        GUICtrlCreateRadio("Wholesale Price", 22, 225)
    $GUIArray[7] =        GUICtrlCreateRadio("Brand", 22, 245)
    $GUIArray[8] =        GUICtrlCreateRadio("Notes", 22, 265)
    $GUIArray[9] =        GUICtrlCreateRadio("Product Search Tags", 22, 285)
    $GuiArray[10] =        GUICtrlCreateRadio("Product Identifiers", 22, 305)
    ;POSTAGE
    $GUIArray[11] =        GUICtrlCreateRadio("Fixed Cost", 22, 350)
    ;SEARCH ENGINE OPTIMISATION
    $GUIArray[12] =        GUICtrlCreateRadio("Title", 22, 395)
    $GUIArray[13] =        GUICtrlCreateRadio("Keywords", 22, 415)
    $GUIArray[14] =        GUICtrlCreateRadio("Description", 22, 435)
    $GUIArray[15] =        GUICtrlCreateRadio("Custom URL", 22, 455)
    ;BUTTONS
    $GUIArray[16] =        GUICtrlCreateButton("View Data", 10, 490, 150, 22)
                        GUICtrlSetOnEvent($GuiArray[16], "_DataGUI")
    $GuiArray[17] =        GUICtrlCreateButton("New Product", 10, 520, 150, 22)
                        GUICtrlSetOnEvent($GuiArray[17], '_ReStart')
    ;STATUSBAR
    $GuiArray[18] =        _GUICtrlStatusBar_Create($GuiArray[0])
                        _GUICtrlStatusBar_SetText($GuiArray[18], $PNum)
    ;GROUPS
    GUICtrlCreateGroup("Basic Details",                    10,        10,        150,    60)
    GUICtrlCreateGroup("Price Details",                    10,        75,        150,    40)
    GUICtrlCreateGroup("Description",                     10,        120,    150,    40)
    GUICtrlCreateGroup("Images",                        10,        165,    150,    40)
    GUICtrlCreateGroup("Advanced Details",                10,        210,    150,    120)
    GUICtrlCreateGroup("Postage",                        10,        335,    150,    40)
    GUICtrlCreateGroup("Search Engine Optimisation",    10,        380,    150,    100)
    ;GUI BEHAVIORS
    GUICtrlSetState($GUIArray[1], 1)
    GUISetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $GuiArray[0])
    ;CONTINUING WITH THE SCRIPT
    If $TestGui = 0 Then
        _Main()
    EndIf
    While 1
    WEnd
EndFunc
Func _Main()
    WinsetOnTop("          ", "", 1)
    If $PBrand = '' Then
        GUICtrlSetState($GuiArray[7], $GUI_DISABLE)
    EndIf
    While 1
        For $Repeat = 1 To 16 ;Getting selected radio box
            If GUICtrlRead($GuiArray[$Repeat]) = 1 Then
            ;    MsgBox(0,"",$Selected)
                $Selected = $Repeat
                ExitLoop
            EndIf
        Next
        Switch $Selected
            Case 1 ;Product Name
                ClipPut($PName)
                While GUICtrlRead($GuiArray[1]) = 1
;~                     If _IsPressed(11) And _IsPressed(56) Then
;~                         GUICtrlSetState($GuiArray[3], $GUI_CHECKED)
;~                     EndIf
                WEnd
            Case 2 ;Product Code
                ClipPut($PNum)
                While GUICtrlRead($GuiArray[2]) = 1
                    If _IsPressed(11) And _IsPressed(56) Then
                        While _IsPressed(11) And _IsPressed(56)
                        WEnd
                        Sleep(100)
                        Send("{TAB}")
                        Send("10")
                    EndIf
                WEnd
            Case 3 ;Product Cost
                ClipPut($PCost)
                While GUICtrlRead($GuiArray[3]) = 1
                WEnd
            Case 4 ;Product Description
                ClipPut($PDetails)
                While GUICtrlRead($GuiArray[4]) = 1
                WEnd
            Case 5 ;Images
                ClipPut($PImagesArray[0])
                $ThisImage = 0
                While GUICtrlRead($GuiArray[5]) = 1
                    If _IsPressed(11) And _IsPressed(56) Then
                        $ThisImage += 1
                        If $ThisImage = UBound($PImagesArray) Then
                            ClipPut("")
                        Else
                            ClipPut($PImagesArray[$ThisImage])
                        EndIf
                    EndIf
                WEnd
            Case 6 ;Wholesale
                ClipPut($PWholeSale)
                While GUICtrlRead($GuiArray[6]) = 1
                WEnd
            Case 7 ;Brand
                ClipPut($PBrand)
                While GUICtrlRead($GuiArray[7]) = 1
                WEnd
            Case 8 ;Notes
                ClipPut('Product Code: '&$PCode)
                While GUICtrlRead($GuiArray[8]) = 1
                WEnd
            Case 9 ;Product Search Tags
                ClipPut(StringLeft($PSearchTags, StringInStr($PSearchTags, "|", 0, 1)-1))
                $ThisPSearchTags = $PSearchTags
                While GUICtrlRead($GuiArray[9]) = 1
                    If _IsPressed(11) And _IsPressed(56) Then
                        Sleep(100)
                        $ThisPSearchTags = StringTrimLeft($ThisPSearchTags, StringInStr($ThisPSearchTags, "|"))
                        ClipPut(StringLeft($ThisPSearchTags, StringInStr($ThisPSearchTags, "|")-1))
                        While _IsPressed(11) And _IsPressed(56)
                        WEnd
                    EndIf
                    If ClipGet() = '' Then
                        While GUICtrlRead($GuiArray[9]) = 1
                        WEnd
                    EndIf
                WEnd
            Case 10 ;Product Identifyer
                ClipPut($PCode)
                While GUICtrlRead($GuiArray[10]) = 1
                WEnd
            Case 11 ;Fixed Cost Postage
                ClipPut($PDelivery)
                While GUICtrlRead($GuiArray[10]) = 1
                WEnd
            Case 12 ;SEO Title
                ClipPut($PName)
                While GUICtrlRead($GuiArray[11]) = 1
                WEnd
            Case 13 ;SEO Keywords
                ClipPut($SEOKeywords)
                While GUICtrlRead($GuiArray[12]) = 1
                WEnd
            Case 14 ;SEO Description
                ClipPut($SEODesc)
                While GUICtrlRead($GuiArray[13]) = 1
                WEnd
            Case 15 ;Custom URL
                ClipPut($PNum)
                While GUICtrlRead($GuiArray[14]) = 1
                WEnd
        EndSwitch
    WEnd
EndFunc
Func _DataGUI()
    $DataGuiArray[0] =        GUICreate("", @DesktopWidth*0.75, @DesktopHeight*0.75, 0, 0, 0x010F0000)
    $DataGuiArray[1] =        GUICtrlCreateListView("Name|Data", 0, 0, @DesktopWidth, @DesktopHeight)
                            GUICtrlSetResizing($GuiArray[1], '102')
    $DataGuiArray[2] =        GUICtrlCreateListViewItem("Product Name|"&$PName, $GuiArray[1])
    $DataGuiArray[3] =        GUICtrlCreateListViewItem("Product Cost|"&$PCost, $GuiArray[1])
    $DataGuiArray[4] =        GUICtrlCreateListViewItem("Delivery Cost|"&$PDelivery, $GuiArray[1])
    $DataGuiArray[5] =        GUICtrlCreateListViewItem("Description|"&$PDetails, $GuiArray[1])
    $DataGuiArray[6] =        GUICtrlCreateListViewItem("Wholesale|"&$PWholeSale, $GuiArray[1])
    If $PBrand = "" Then
        $DataGuiArray[7] = GUICtrlCreateListViewItem("Brand|BRAND UNKNOWN", $GuiArray[1])
        GUICtrlSetBkColor($DataGuiArray[7], 0xff5040)
    Else
        $DataGuiArray[7] = GUICtrlCreateListViewItem("Brand|"&$PBrand, $DataGuiArray[1])
    EndIf
    $DataGuiArray[8] = GUICtrlCreateListViewItem("Warranty|"&$PWarranty, $DataGuiArray[1])
    GuiSetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $DataGuiArray[0])
    Return
EndFunc
Func _HTMLGetElementByID($html_code, $div_id)
    Local $o_htmlfile = ObjCreate('HTMLFILE')
    If Not IsObj($o_htmlfile) Then
        Return SetError(-1, 0, '')
    EndIf
    $o_htmlfile.open()
    $o_htmlfile.write($html_code)
    $o_htmlfile.close()
    Local $div = $o_htmlfile.getElementByID($div_id)
    If Not IsObj($div) Then
        Return SetError(0, 0, '')
    EndIf
    Return $div.outerHTML
EndFunc
Func _HTMLGetDescription($Desc, $Warranty)
    $Desc = StringStripWS($Desc, 3)
    $Desc = StringReplace($Desc, "<p>", "")
    $Desc = StringReplace($Desc, "</p>", "<br />")
    $Title = StringTrimLeft($Desc, StringInStr($Desc, '<h2>')+3)
    $Title = StringTrimRight($Title, StringLen($Title) - StringInStr($Title, '</h2>')+1)
    $Title = '<div style="text-align: center;"><strong><span style="font-size: 20px; font-family: arial; color: #3333ff;">'&$Title&'</span></strong></div>'
;~     MsgBox(0, "Title", $Title)
    $Desc = StringTrimRight($Desc, (StringLen($Desc) - StringInStr($Desc, "<h4"))+1)
    $Desc = '<span style="font-size: 12px; font-family: arial;"><br />'&StringTrimLeft($Desc, StringInStr($Desc, "<DIV class=clear></DIV>")+24)
    $DescBody = StringLeft($Desc, StringInStr($Desc, '<h3>')-1)
;~     MsgBox(0, "DescBody", $DescBody)
    $Desc = StringTrimLeft($Desc, StringInStr($Desc, '<h3>')-1)
    $Desc = StringReplace($Desc, "<h3>", "<strong>")
    $Desc = StringReplace($Desc, "</h3>", "</strong>")
    $Desc = StringReplace($Desc, '<strong>Product Features</strong>', '<strong>Product Features</strong>')
    $Desc = StringReplace($Desc, '<strong>Features</strong>', '<strong>Product Features</strong>')
    $Desc = StringReplace($Desc, "<strong>Specifications</strong>", "<strong>Product Specifications</strong>")
    $Desc = StringReplace($Desc, "<strong>Contents</strong>", "<strong>Package Contents</strong>")
    $Desc = StringReplace($Desc, "<strong>Package Contains</strong>", "<strong>Package Contents</strong>")
    $Desc = StringReplace($Desc, "<strong>Contains</strong>", "<strong>Package Contents</strong>")
    If $Warranty = "This product comes with a warranty covered by either oo.com.au or the supplier of this product." Then
        $Desc &= "This product comes with a warranty.</span>"
    Else
        $Desc &= $Warranty&"</span>"
    EndIf
    $Desc = StringReplace($Desc, '</li></ul>', '</li>'&@CRLF&'</ul>')
    $DescBody = StringStripWS($DescBody, 7)
    While StringRight($DescBody, 6) = '<br />'
        $DescBody = StringTrimRight($DescBody, 6)
        $DescBody = StringStripWS($DescBody, 7)
    WEnd
    While StringRight($DescBody, 6) = '<br /><br />'
        $DescBody = StringReplace($DescBody, '<br /><br />', '<br />')
        $DescBody = StringStripWS($DescBody, 7)
    WEnd
    $DescBody = StringReplace($DescBody, '<br />', '<br /><br />'&@CRLF)
    $DescArray = StringSplit($Desc, @CR&@LF&@CRLF, 2)
;~     _ArrayDisplay($DescArray)
    $Desc = ""
    For $Repeat = 0 To UBound($DescArray)-1
        $DescArray[$Repeat] = StringStripWS($DescArray[$Repeat], 3)
        If StringLeft($DescArray[$Repeat], 5) = '    <li>' And StringRight($DescArray[$Repeat], 5) <> '</li>' Then
            $DescArray[$Repeat] =  '    '&$DescArray[$Repeat]&'</li>'
        EndIf
        If $DescArray[$Repeat] <> "" Then
            $Desc &= $DescArray[$Repeat]&@CRLF
        EndIf
    Next
;~     MsgBox(0, "DotPoints", $Desc)
    $Title        = StringStripWS($Title, 3)
    $DescBody    = StringStripWS($DescBody, 3)&'<br /><br />'
    $Desc        = StringStripWS($Desc, 3)
    $Desc = StringReplace($Desc, '<li>', '    <li>')
    $Desc = StringReplace($Desc, '</li>', '</li>')
    $Desc = StringReplace($Desc, '<strong>', '<strong>')
    $Desc = StringReplace($Desc, '</strong>', '</strong>')
    $Desc = StringReplace($Desc, '<ul>', '<ul>')
    $Desc = StringReplace($Desc, '</ul>', '</ul>')
    Return $Title&@CRLF&$DescBody&@CRLF&$Desc
EndFunc
Func _HTMLGetProductCode($Desc)
    $Code = StringTrimRight($Desc, StringLen($Desc)-StringInStr($Desc, '</h4>')+1)
    $Code = StringRight($Code, StringLen($Code) - StringInStr($Code, 'Product Code:')-13)
    Return $Code
EndFunc
Func _HTMLGetImages($Images)
    $Images = StringTrimLeft($Images, StringInStr($Images, 'http')-1)
    Local $ImagesString = StringLeft($Images, StringInStr($Images, '.jpg')+3)&'|'
    While StringLeft($Images, StringInStr($Images, '.jpg')+3) <> StringRight($ImagesString, StringLen($ImagesString) - StringInStr($ImagesString, '|', 0, 1))&'|'
        If StringInStr($Images, 'http', 0, 2)-1 = '-1' Then
            ExitLoop
        EndIf
        $Images = StringTrimLeft($Images, StringInStr($Images, 'http', 0, 2)-1)
        $ImagesString &= StringLeft($Images, StringInStr($Images, '.jpg')+3)&'|'
    WEnd
    $ImagesString = StringTrimRight($ImagesString, 1)
;~     MsgBox(0,"", $Images)
;~     MsgBox(0,"Images",$ImagesString)
    Return $ImagesString
EndFunc
Func _HTMLGetBrand($Desc)
    Local $Brand = ""
    If StringInStr($Desc, '<div class="brand">') Then
        $Brand = StringTrimRight(StringTrimLeft($Desc, StringInStr($Desc, '<div class="brand">')-1), StringLen($Desc) - StringInStr($Desc, "</a>", 0, 2)+1)
        $Brand = StringRight($Brand, StringLen($Brand) - StringInStr($Brand, "More ")-4)
    ElseIf StringInStr($Desc, '<div class=brand>') Then
        $Brand = StringTrimRight(StringTrimLeft($Desc, StringInStr($Desc, '<div class=brand>')-1), StringLen($Desc) - StringInStr($Desc, "</a>", 0, 2)+1)
        $Brand = StringRight($Brand, StringLen($Brand) - StringInStr($Brand, "More ")-4)
    ElseIf StringInStr($Desc, 'Brand: ') Then
        $Brand = StringTrimLeft($Desc, StringInStr($Desc, 'Brand: ')+6)
        $Brand = StringLeft($Brand, StringInStr($Brand, '</li>')-1)
    EndIf
    Return $Brand
EndFunc
Func _HTMLGetWarranty($Warranty)
    $Warranty = StringTrimLeft(StringTrimRight($Warranty, StringLen($Warranty) - StringInStr($Warranty, '</p>')+1), StringInStr($Warranty, '<p>')+2)
    If $Warranty = 'This product comes with a warranty covered by either oo.com.au or the supplier of this product.' Then
        $Warranty = 'This product comes with a warranty.'
    EndIf
    Return $Warranty
EndFunc
Func _HTMLGetCost($Main)
    If StringInStr($Main, '<P class=was>') Then
        $Cost = StringTrimRight(StringTrimLeft($Main, StringInStr($Main, '<P class=was>')+24), StringLen(StringTrimLeft($Main, StringInStr($Main, '<P class=was>')+24))-StringInStr(StringTrimLeft($Main, StringInStr($Main, '<P class=was>')+24), '</span>')+1)
    Else
        $Cost =    StringTrimLeft(StringTrimRight($Main, StringLen($Main)-StringInStr($Main, "</strong>")+1), StringInStr($Main, "<P class=price>Our Price: <strong>")+34)
    EndIf
    Return $Cost
EndFunc
Func _Images()
    Local $Image, $Width, $Height
;~    _ArrayDisplay($PImagesArray)
    $ImagesGuiArray[0]    =    GUICreate("Images", 600, 680)
                            GUISetBkColor(0xd0d0d0, $ImagesGuiArray[0])
    $ImagesGuiArray[1]    =    GUICtrlCreateButton("<", 245, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[1], '_PrevImage')
    $ImagesGuiArray[2]    =    GUICtrlCreateButton("Edit", 285, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[2], '_EditImage')
    $ImagesGuiArray[3]    =    GUICtrlCreateButton(">", 325, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[3], '_NextImage')
    $ImagesGuiArray[4]    =    GUICtrlCreateLabel("", 245, 645, 105, 30, 0x01)
    GUICtrlSetState($ImagesGuiArray[1], 128)
    If UBound($PImagesArray) = 1 Then
        GUICtrlSetState($ImagesGuiArray[3], 128)
    EndIf
    If UBound($PImagesArray)>8 Then
        $PImagesArrayLimit = 8
    Else
        $PImagesArrayLimit = UBound($PImagesArray)-1
    EndIf
    _CreateImage()
    GUISetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $ImagesGuiArray[0])
    While 1
    WEnd
EndFunc
Func _CreateImage()
    If StringLeft($PImagesArray[0], 4) = 'http' Then
        InetGet($PImagesArray[0], @TempDir&"\Pic.jpg", 16, 0)
    Else
        FileWrite(@TempDir&"\Pic.jpg", FileRead($ImagesDirectory&"\"&$PNum&" 0.jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"\Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Width = 600
    ElseIf $Height > $Width Then
        $Width = 600*($Height/$Width)
        $Height = 600
    Else
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    $Pic = GUICtrlCreatePic(@TempDir&"\Pic.jpg", 0, 0, $Width, $Height)
    $ThisImage = 0
    GUICtrlSetData($ImagesGuiArray[4], "Image 1 of "&UBound($PImagesArray))
    Return
EndFunc
Func _NextImage()
    GUICtrlSetState($ImagesGuiArray[1], 255)
    $ThisImage += 1
    GUICtrlSetData($ImagesGuiArray[4], "Image "&$ThisImage&" of "&UBound($PImagesArray))
    If StringLeft($PImagesArray[$ThisImage], 4) = 'http' Then
        InetGet($PImagesArray[$ThisImage], @TempDir&"\Pic.jpg", 16, 0)
    Else
        FileDelete(@TempDir&"\Pic.jpg")
        FileWrite(@TempDir&"\Pic.jpg", FileRead($ImagesDirectory&"\"&$PNum&" "&$ThisImage&".jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"\Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    GUICtrlDelete($Pic)
    $Pic = GUICtrlCreatePic(@TempDir&"\Pic.jpg", $Left, $Top, $Width, $Height)
    If $ThisImage = UBound($PImagesArray)-1 Then
        GUICtrlSetState($ImagesGuiArray[3], 128)
    EndIf
    Return
EndFunc
Func _EditImage()
    Local $Label, $ImageURL
    GUICtrlDelete($Pic)
    $Label = GUICtrlCreateLabel("Waiting for Microsoft Paint to close.", 220, 290)
    RunWait("mspaint "&@TempDir&"\Pic.jpg", @TempDir, @SW_SHOW)
    $PImagesArray[$ThisImage] = $ImagesDirectory&"\"&$PNum&" "&$ThisImage&".jpg"
    FileDelete($ImagesDirectory&"\"&$PNum&" "&$ThisImage&".jpg")
    FileWrite($ImagesDirectory&"\"&$PNum&" "&$ThisImage&".jpg", FileRead(@TempDir&"\Pic.jpg"))
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"\Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    $Pic = GUICtrlCreatePic(@TempDir&"\Pic.jpg", $Left, $Top, $Width, $Height)
    GUICtrlDelete($Label)
EndFunc
Func _PrevImage()
    GUICtrlSetState($ImagesGuiArray[3], 255)
    $ThisImage -= 1
    GUICtrlSetData($ImagesGuiArray[4], "Image "&$ThisImage&" of "&UBound($PImagesArray))
    If StringInStr($PImagesArray[$ThisImage], 'http') Then
        InetGet($PImagesArray[$ThisImage], @TempDir&"\Pic.jpg", 16, 0)
    Else
        FileDelete(@TempDir&"\Pic.jpg")
        FileWrite(@TempDir&"\Pic.jpg", FileRead($ImagesDirectory&"\"&$PNum&" "&$ThisImage&".jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"\Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    GUICtrlDelete($Pic)
    $Pic = GUICtrlCreatePic(@TempDir&"\Pic.jpg", $Left, $Top, $Width, $Height)
    If $ThisImage = 0 Then
        GUICtrlSetState($ImagesGuiArray[1], 128)
    EndIf
    Return
EndFunc
Func _Price($FinalPrice)
    $FinalPrice = 1.3*$FinalPrice
    If $FinalPrice > 15 Then
        Local $FinalPriceArray = StringSplit($FinalPrice, ".", 3)
        If UBound($FinalPriceArray) = 1 Then
            _ArrayAdd($FinalPriceArray, 0)
        EndIf
        If StringRight($FinalPriceArray[0], 1) & "." & $FinalPriceArray[1] >= 2.45 And StringRight($FinalPriceArray[0], 1) & "." & $FinalPriceArray[1] < 7.45 Then
            $FinalPrice = StringLeft($FinalPriceArray[0], StringLen($FinalPriceArray[0])-1)&"4.95"
        Else
            If StringRight($FinalPriceArray[0], 1) > 5 Then
                $FinalPrice = StringLeft($FinalPriceArray[0], StringLen($FinalPriceArray[0])-1)&"9.95"
            Else
                $FinalPrice = (StringLeft($FinalPriceArray[0], StringLen($FinalPriceArray[0])-1)&"9.95")-10
            EndIf
        EndIf
    EndIf
;~    MsgBox(0,"",$FinalPrice)
    Return $FinalPrice
EndFunc
Func _GetSearchTags($SearchTags)
    Local $DontAllow[4] = [" ", ",", "-", "&amp"]
    For $Repeat = 0 To UBound($DontAllow)-1
        $SearchTags = StringReplace($SearchTags, $DontAllow[$Repeat], "|")
    Next
    While StringInStr($SearchTags, "||")
        $SearchTags = StringReplace($SearchTags, "||", "|")
    WEnd
    Return $SearchTags
EndFunc
Func _GetSEOKeywords($Keywords)
    Local $DontAllow[4] = [" ", ",", "-", "&amp"]
    For $Repeat = 0 To UBound($DontAllow)-1
        $Keywords = StringReplace($Keywords, $DontAllow[$Repeat], ",")
    Next
    While StringInStr($Keywords, ",,")
        $Keywords = StringReplace($Keywords, ",,", ",")
    WEnd
    Return $Keywords
EndFunc
Func _Exit()
    Switch @GUI_WinHandle
        Case $GuiArray[0]
            Exit
        Case $ImagesGuiArray[0]
            GUIDelete($ImagesGuiArray[0])
            _CreateGUI()
        Case $ProdNumGuiArray[0]
            $Exit = MsgBox(4,"Exit Now?", "Are you sure you want to exit?")
            If $Exit = 6 Then
                Exit
            Else
                Return
            EndIf
        Case Else
            GUIDelete(@GUI_WinHandle)
            ;DataGuiArray[0]
    EndSwitch
EndFunc
Func _OnExit()
    GUIDelete($GuiArray[0])
    _GDIPlus_Shutdown()
EndFunc
Func _Delivery($Main)
    Local $Delivery
    ;$Delivery =    StringTrimLeft($PMain, StringInStr($PMain, '<p class=delivery>', 0)+36)
    ;$Delivery = StringTrimRight(StringTrimLeft($Delivery, StringInStr($Delivery, "$")-1), StringLen($Delivery)-StringInStr($Delivery, ".")-2)
    Local $Delivery = StringRegExp($Main, '<P class=delivery>([\S\s]*?)<\/P>', 1)
    $Delivery = StringRegExp($Delivery[0], '<STRONG>([\S]+)<\/STRONG>', 1)
    $Delivery[0] = StringTrimLeft($Delivery[0], 1)
;~     MsgBox(0,"",$Delivery[0])
    Return $Delivery[0]
EndFunc
Func _GetSEODescription($Desc2)
    $Desc2 = _HTML2PlainText($Desc2);StringRegExpReplace($Desc2, "(<[^>]+?>)", "")
    $Desc2 = _RemExtraLineBreaks($Desc2);StringReplace($Desc2, @CRLF&@CRLF, @CRLF, 0)
    Return $Desc2
EndFunc
Func _HTML2PlainText($sHtml)
    $sHtml = StringRegExpReplace($sHtml, "<br[^>]*\/>", @CRLF)
    $sHtml = StringRegExpReplace($sHtml, "<\/?p[^>]*>", @CRLF & @CRLF)
    $sHtml = StringRegExpReplace($sHtml, '(<[^>]+>)', '')
    Return $sHtml
EndFunc
Func _RemExtraLineBreaks($sTxt)
    $sTxt = StringRegExpReplace($sTxt, "[\s][\s]+", @CRLF)
    Return $sTxt
EndFunc
Func _IsURL($URL)
    Select
        Case StringInStr($URL, ".com")
            Return True
        Case StringInStr($URL, ".net")
            Return True
        Case StringInStr($URL, ".org")
            Return True
        Case StringInStr($URL, ".gov")
            Return True
        Case StringInStr($URL, ".edu")
            Return True
        Case StringInStr($URL, ".biz")
            Return True
        Case Else
            Return False
    EndSelect
EndFunc
Func _Restart()
    GUIDelete($GuIArray[0])
    _Start()
EndFunc

Does anybody have the same problem?

Thanks.

Link to comment
Share on other sites

  • Moderators

Mikeman27294,

On a quick look through you script it seems that you are permanently running within a function and never return to a While...WEnd idle loop in the main code. In this case Autoit does indeed queue the GUI events and will only honour other events once the running function is ended. The Interrupting a running function tutorial in the Wiki exlains in more detail. :)

You might also like to take a look at this thread where I have been explaining the same thing. ;)

Possible solutions? The most obvious are: rewrite your code to return to a While...WEnd idle loop in the main code so that AutoIt will honour other events as they occur; use one of the techniques in the Wiki tutorial to detect the events and interrupt your running function. :)

If I can help further please ask. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Yes, it does include a while loop in the main function (but I don't blame you for not noticing it, the code is like a jungle :)

What it should do, is download a webpage, then present the user with the images GUI. When that is closed, it should them present a GUI on the right hand side of the screen. While either GUI is active, it should be inside a while loop.

Link to comment
Share on other sites

  • Moderators

Mikeman27294

Yes, it does include a while loop in the main function

That is exactly my point. Read what I said above in my post above:

a While...WEnd idle loop in the main code

In your case the While...WEnd loops are all inside functions. So you never leave a function once the script is running and as a result AutoIt queues subsequent events until you finally leave the function on exit. ;)

Did you read the Wiki tutorial or look at the other thread? :)

It is all clearly explained in the tutorial so I am not going to repeat it all here - please take a look and you will soon see what is happening. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Oh you meant a while loop outside of a function. I understand about how AutoIT queues the functions till the end of the while loop, but what I mean to say is happening with my script, is that it is running the while loop continuously, and completely disregarding the fact that I clicked on the button. I know this because I have run it through the graphical AutoIT debugger, and it shows that it is returning to the top of the while loop and running the while loop until I tell it to exit. Then it continues with the script.

Link to comment
Share on other sites

  • Moderators

Mikeman27294,

it is running the while loop continuously, and completely disregarding the fact that I clicked on the button

How many times do I have to say this: :)

If you are in a running function, AutoIt does not honour GUI events but queues them until you leave the function and return to the main code.

As your While...WEnd loops are all inside functions, AutoIt behaves as I have just described and queues the events. To get over this you need to use the tricks which are described in the tutorial to which i linked. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Mikeman27294,

If you can get rid of all the non-essential code in your script so you just have the GUIs and the controls, I would be happy to help you sort it out. At the moment there is, as you put it earlier, too much "jungle" in there. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Ok, I have changed it, like so:

#AutoIt3Wrapper_UseX64=N
#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <Misc.au3>
#include <String.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnEsc", 0)
Opt("TrayAutoPause", 0)
_GDIPlus_Startup()
OnAutoItExitRegister('_OnExit')
Global $TestGui = 0, $DataGuiArray[10], $ProdNumGuiArray[6], $GUIArray[19], $Selected, $FilePath, $File, $Product, $PInfo, $PWarranty, $PDetails, $PCode, $PWrap, $PMain, $PName, $PCost, $PImages, $ImagesString, $Repeat, $PDetails, $PBrand, $PDelivery, $PWholeSale, $PSearchTags, $PWholesale, $SEOKeywords, $SEODesc, $PNum = "NO PRODUCT NUMBER", $PNumLimit, $MichaelBot = "MichaelBot/1.0 (+http://http://www.Michaelonline.com.au/)", $ThisImage = 0, $Pic, $ImagesGuiArray[5], $ImagesDirectory = "C:Users"&@UserName&"DesktopImages", $PImagesArray
Global $UsePNum = 0, $Mode = 0
HttpSetUserAgent($MichaelBot)
If $TestGui = 1 Then
    _CreateGUI()
EndIf
If $UsePNum = 1 Then
    _ProdNum()
EndIf
_Start()
_GetData()
_Images()
While $ImagesGuiArray[0] <> -1
WEnd
WinsetOnTop("         ", "", 1)
If $PBrand = '' Then
    GUICtrlSetState($GuiArray[7], $GUI_DISABLE)
EndIf
While 1
    For $Repeat = 1 To 16 ;Getting selected radio box
        If GUICtrlRead($GuiArray[$Repeat]) = 1 Then
        ;   MsgBox(0,"",$Selected)
            $Selected = $Repeat
            ExitLoop
        EndIf
    Next
    Switch $Selected
        Case 1 ;Product Name
            ClipPut($PName)
            While GUICtrlRead($GuiArray[1]) = 1
;~               If _IsPressed(11) And _IsPressed(56) Then
;~                   GUICtrlSetState($GuiArray[3], $GUI_CHECKED)
;~               EndIf
            WEnd
        Case 2 ;Product Code
            ClipPut($PNum)
            While GUICtrlRead($GuiArray[2]) = 1
                If _IsPressed(11) And _IsPressed(56) Then
                    While _IsPressed(11) And _IsPressed(56)
                    WEnd
                    Sleep(100)
                    Send("{TAB}")
                    Send("10")
                EndIf
            WEnd
        Case 3 ;Product Cost
            ClipPut($PCost)
            While GUICtrlRead($GuiArray[3]) = 1
            WEnd
        Case 4 ;Product Description
            ClipPut($PDetails)
            While GUICtrlRead($GuiArray[4]) = 1
            WEnd
        Case 5 ;Images
            ClipPut($PImagesArray[0])
            $ThisImage = 0
            While GUICtrlRead($GuiArray[5]) = 1
                If _IsPressed(11) And _IsPressed(56) Then
                    $ThisImage += 1
                    If $ThisImage = UBound($PImagesArray) Then
                        ClipPut("")
                    Else
                        ClipPut($PImagesArray[$ThisImage])
                    EndIf
                EndIf
            WEnd
        Case 6 ;Wholesale
            ClipPut($PWholeSale)
            While GUICtrlRead($GuiArray[6]) = 1
            WEnd
        Case 7 ;Brand
            ClipPut($PBrand)
            While GUICtrlRead($GuiArray[7]) = 1
            WEnd
        Case 8 ;Notes
            ClipPut('Product Code: '&$PCode)
            While GUICtrlRead($GuiArray[8]) = 1
            WEnd
        Case 9 ;Product Search Tags
            ClipPut(StringLeft($PSearchTags, StringInStr($PSearchTags, "|", 0, 1)-1))
            $ThisPSearchTags = $PSearchTags
            While GUICtrlRead($GuiArray[9]) = 1
                If _IsPressed(11) And _IsPressed(56) Then
                    Sleep(100)
                    $ThisPSearchTags = StringTrimLeft($ThisPSearchTags, StringInStr($ThisPSearchTags, "|"))
                    ClipPut(StringLeft($ThisPSearchTags, StringInStr($ThisPSearchTags, "|")-1))
                    While _IsPressed(11) And _IsPressed(56)
                    WEnd
                EndIf
                If ClipGet() = '' Then
                    While GUICtrlRead($GuiArray[9]) = 1
                    WEnd
                EndIf
            WEnd
        Case 10 ;Product Identifyer
            ClipPut($PCode)
            While GUICtrlRead($GuiArray[10]) = 1
            WEnd
        Case 11 ;Fixed Cost Postage
            ClipPut($PDelivery)
            While GUICtrlRead($GuiArray[10]) = 1
            WEnd
        Case 12 ;SEO Title
            ClipPut($PName)
            While GUICtrlRead($GuiArray[11]) = 1
            WEnd
        Case 13 ;SEO Keywords
            ClipPut($SEOKeywords)
            While GUICtrlRead($GuiArray[12]) = 1
            WEnd
        Case 14 ;SEO Description
            ClipPut($SEODesc)
            While GUICtrlRead($GuiArray[13]) = 1
            WEnd
        Case 15 ;Custom URL
            ClipPut($PNum)
            While GUICtrlRead($GuiArray[14]) = 1
            WEnd
    EndSwitch
WEnd
Func _ProdNum()
    $ProdNumGuiArray[0] = GUICreate("Automatic Product Numbers", 120, 120)
    $ProdNumGuiArray[1] = GUICtrlCreateLabel("From", 20, 20, 30, 21)
    $ProdNumGuiArray[2] = GUICtrlCreateInput("", 50, 17, 50, 21)
    $ProdNumGuiArray[3] = GUICtrlCreateLabel("To", 20, 50, 21)
    $ProdNumGuiArray[4] = GUICtrlCreateInput("", 50, 47, 50, 21)
    $ProdNumGuiArray[5] = GUICtrlCreateButton("OK", 40, 80, 40, 30)
    GUICtrlSetOnEvent($ProdNumGuiArray[5], "_CheckProdNum")
    GUISetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $ProdNumGuiArray[0])
    Local $Msg = 0
    While 1
    WEnd
EndFunc
Func _CheckProdNum()
    GUISetState(@SW_HIDE, $ProdNumGuiArray[0])
    If GUICtrlRead($ProdNumGuiArray[2]) = "" Or GUICtrlRead($ProdNumGuiArray[4]) = "" Then
        MsgBox(0,"","Please insert a number in both input boxes.")
    Else
        If Number(GUICtrlRead($ProdNumGuiArray[2])) > Number(GUICtrlRead($ProdNumGuiArray[4])) Then
            MsgBox(0,"","The first number should be smaller than the second.")
        Else
            $PNum = Number(GUICtrlRead($ProdNumGuiArray[2]))
            $PNum -= 1
            $PNumLimit = Number(GUICtrlRead($ProdNumGuiArray[4]))
            GUIDelete($ProdNumGuiArray[0])
            _Start()
        EndIf
    EndIf
EndFunc
Func _Start()
    If $UsePNum = 1 Then
        If $PNum <> "NO PRODUCT NUMBER" Then
            If $PNum > $PNumLimit Then
                _ProdNum()
            Else
                $PNum += 1
            EndIf
        EndIf
    EndIf
    Local $URL = 'http://www.oo.com.au/Vivitar-iTwist-X018-Digital-Ca_P42902C901.cfm';InputBox("URL", "Please input the product's URL.", ClipGet())
    If $URL = "" Then
        MsgBox(0,"","No URL Supplied.")
        _Start()
    EndIf
    If Not _IsURL($URL) Then
        MsgBox(0,"","Given string is not URL.")
        _Start()
    EndIf
    If StringInStr($URL, "?") Then
        $URL = StringLeft($URL, StringInStr($URL, "?"))
    EndIf
    If Not StringInStr($URL, "http://") Then
        $URL = 'http://'&$URL
    EndIf
    Local $FilePath = @ScriptDir&"FileFile.html"
;~   ABOVE IS VALIDATION FOR THE URL
    ClipPut("")
;~   DOWNLOADING THE WEBPAGE
    InetGet($URL, $FilePath, 16, 0)
    If FileExists(@ScriptDir&"FileFile.htm") Then
        FileMove(@ScriptDir&"FileFile.htm", $FilePath, 9)
    EndIf
;~   ENSURING THAT THE CORRECT FILE EXISTS
    $File=FileRead($FilePath)
;~   GETTING THE FILE CONTENTS
    If $File = '' Then
;~       IF FILE NOT DOWNLOADED FROM OO ATTEMPT DOWNLOAD FROM GOOGLE CACHE
        MsgBox(0,"Error","Could Not Download from OO.com.au"&@CRLF&"Now attempting download from Google Cache.")
        If StringInStr($URL, 'http://') Then
;~           REMOVE HTTP FROM URL
            $URL = StringTrimLeft($URL, 7)
        EndIf
        $URL = StringTrimRight($URL, 9)&".cfm"
;~       REMOVE ARGUMENTS AND PARAMETERS FROM URL
        HttpSetUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1')
;~       SET USER AGENT TO FIREFOX TO AVOID GOOGLE CACHE ERRORS
        InetGet('http://webcache.googleusercontent.com/search?q=cache:'&$URL, $FilePath, 16, 0)
;~       ATTEMPT TO DOWNLOAD FILE FROM GOOGLE CACHE
        If FileExists(@ScriptDir&"FileFile.htm") Then
            FileMove(@ScriptDir&"FileFile.htm", $FilePath, 9)
        EndIf
;~       ENSURING THAT THE CORRECT FILE EXISTS
        HttpSetUserAgent($MichaelBot)
;~       RESETTING THE USER AGENT TO MichaelBOT
        $File=FileRead($FilePath)
;~       GETTING THE FILE CONTENTS
        If $File = '' Then
;~           IF FILE NOT DOWNLOADED FROM GOOGLE CACHE THEN DOWNLOAD MANUALLY
            MsgBox(0,"Error","Could Not Download from Google Cache"&@CRLF&"Please save the file manually to "&$FilePath&".")
            While Not FileExists($FilePath)
                If FileExists(@ScriptDir&"FileFile.htm") Then
                    FileMove(@ScriptDir&"FileFile.htm", $FilePath, 9)
                EndIf
;~               ENSURING THAT THE CORRECT FILE EXISTS
                Sleep(1000)
            WEnd
;~           WAITING FOR USER TO DOWNLOAD FILE
            MsgBox(0,"","File detected. Attempting to use file as source.")
            $File=FileRead($FilePath)
;~           GETTING THE FILE CONTENTS
            If StringInStr(StringStripWS($File, 8), "Ashardaswetrywestillaren'tperfect.Wesuggestthatyoutryagainorcontactus.We'resorryforanyinconveniencethismaycause.We'lltryourbesttomakesureitdoesnothappenagain.") Then
                MsgBox(0,"ERROR","It appears that OO.com.au is down!"&@CRLF&"Attempting alternate download methods.")
            EndIf
            If $File = '' Or StringInStr(StringStripWS($File, 8), "Ashardaswetrywestillaren'tperfect.Wesuggestthatyoutryagainorcontactus.We'resorryforanyinconveniencethismaycause.We'lltryourbesttomakesureitdoesnothappenagain.") Then
;~               IF OO IS OFFLINE OR IF USER COULD NOT DOWNLOAD FROM OO
                $Msgbox = MsgBox(4,"Error", "Program could not read contents of file."&@CRLF&"Would you like to attempt to manually load the file's HTML into the program?")
;~               PRESENT USER WITH THE OPTION TO PASTE THE HTML INTO THE PROGRAM
                If $Msgbox = 6 Then
;~                   IF USER ACCEPTS
                    $File = InputBox("Insert HTML", "Please insert the page's source.", "")
;~                   PRESENT USER WITH AN INPUT BOX TO PASTE THE HTML
                    If $File = '' Then
;~                       IF THE USER PASTED NOTHING
                        MsgBox(0,"","Failed to retrieve page source from input box."&@CRLF&"Now Exiting.")
                        Exit
;~                       GIVE UP ON THE USER. MIGHT BE A GOOD IDEA TO BE PERSISTENT AND PLACE IN WHILE LOOP-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                    EndIf
                Else
;~                   IF USER DECLINES
                    MsgBox(0,"","As the program could not retrieve the requested data, it will not exit.")
                    Exit
;~                   EXIT
                EndIf
            EndIf
        EndIf
    EndIf
    If StringInStr($File, 'images/refurbished.gif') Then
;~       ENSURE THAT THE PRODUCT IS NOT REFURBISHED
        MsgBox(0,"REFURBISHED", "Error - This product has been refurbished!");http://www.oo.com.au/Kodak-M531-Digital-Camera-14_P89056C901.cfm
;~       FileDelete($File)
        _Start()
;~       IF THE PRODUCT IS REFURBISHED, THEN MOVE USER ON TO NEXT PRODUCT
    EndIf
;~  MsgBox(0,"",$File)
;~  FileDelete($FilePath)
EndFunc
Func _GetData()
    $ThisImage = 0
    $Pic = 0
    $Product =                  _HTMLGetElementByID($File, 'product')
        $PInfo =                _HTMLGetElementByID($Product, 'p_info')
            $PWarranty =        _HTMLGetElementByID($PInfo, 'p_warranty')
                $PWarranty =    _HTMLGetWarranty($PWarranty)
            $PDetails =         _HTMLGetElementByID($PInfo, 'p_details')
                $PBrand =       _HTMLGetBrand($PDetails)
                If $PBrand = '' Then $PBrand = 'Michael'
                $PCode =        _HTMLGetProductCode($PDetails)
        $PWrap =                _HTMLGetElementByID($Product, 'p_wrap')
            $PMain =            _HTMLGetElementByID($PWrap, 'p_main')
                $PName =        StringTrimLeft(StringTrimRight($PMain, StringLen($PMain) - StringInStr($PMain, '</h1>')+1), StringInStr($PMain, '<h1>')+3)
                $PCost =        _HTMLGetCost($PMain)
                $PWholeSale = $PCost
                $PCost = _Price($PCost)
                $PDelivery =    _Delivery($PMain)
            $PImages =          _HTMLGetElementByID($PWrap, 'p_imgs')
                $PImages =      _HTMLGetImages($PImages)
                $PImagesArray = StringSplit($PImages, "|", 3)
;~               MsgBox(0,"",$PCode)
                For $Repeat = 0 To UBound($PImagesArray)-1
                    $PImagesArray[$Repeat] = 'http://img.oo.com.au/prod/'&$PCode&'/'&$Repeat+1&'b.jpg'
                Next
                $PDetails =     _HTMLGetDescription($PDetails, $PWarranty)
                $PSearchTags =  _GetSearchTags($PName)
                $SEOKeywords =  _GetSEOKeywords($PName)
                $SEODesc =      _GetSEODescription($PDetails)
EndFunc
Func _CreateGUI()
    ;GUI WINDOW
    $GUIArray[0] =      GUICreate("       ", 170, 580, @DesktopWidth-200, 75)
                        WinSetOnTop($GuiArray[0], "", 1)
    ;BASIC DETAILS
    $GUIArray[1] =      GUICtrlCreateRadio("Product Name", 22, 25)
    $GUIArray[2] =      GUICtrlCreateRadio("Product Code", 22, 45)
    ;PRICE DETAILS
    $GUIArray[3] =      GUICtrlCreateRadio("Final Price", 22, 90)
    ;DESCRIPTION
    $GUIArray[4] =      GUICtrlCreateRadio("Description", 22, 135)
    ;IMAGES
    $GUIArray[5] =      GUICtrlCreateRadio("Images", 22, 180) ;Copies the image URL into an array
    ;ADVANCED DETAILS
    $GUIArray[6] =      GUICtrlCreateRadio("Wholesale Price", 22, 225)
    $GUIArray[7] =      GUICtrlCreateRadio("Brand", 22, 245)
    $GUIArray[8] =      GUICtrlCreateRadio("Notes", 22, 265)
    $GUIArray[9] =      GUICtrlCreateRadio("Product Search Tags", 22, 285)
    $GuiArray[10] =     GUICtrlCreateRadio("Product Identifiers", 22, 305)
    ;POSTAGE
    $GUIArray[11] =     GUICtrlCreateRadio("Fixed Cost", 22, 350)
    ;SEARCH ENGINE OPTIMISATION
    $GUIArray[12] =     GUICtrlCreateRadio("Title", 22, 395)
    $GUIArray[13] =     GUICtrlCreateRadio("Keywords", 22, 415)
    $GUIArray[14] =     GUICtrlCreateRadio("Description", 22, 435)
    $GUIArray[15] =     GUICtrlCreateRadio("Custom URL", 22, 455)
    ;BUTTONS
    $GUIArray[16] =     GUICtrlCreateButton("View Data", 10, 490, 150, 22)
                        GUICtrlSetOnEvent($GuiArray[16], "_DataGUI")
    $GuiArray[17] =     GUICtrlCreateButton("New Product", 10, 520, 150, 22)
                        GUICtrlSetOnEvent($GuiArray[17], '_ReStart')
    ;STATUSBAR
    $GuiArray[18] =     _GUICtrlStatusBar_Create($GuiArray[0])
                        _GUICtrlStatusBar_SetText($GuiArray[18], $PNum)
    ;GROUPS
    GUICtrlCreateGroup("Basic Details",                 10,     10,     150,    60)
    GUICtrlCreateGroup("Price Details",                 10,     75,     150,    40)
    GUICtrlCreateGroup("Description",                    10,        120,    150,    40)
    GUICtrlCreateGroup("Images",                        10,     165,    150,    40)
    GUICtrlCreateGroup("Advanced Details",              10,     210,    150,    120)
    GUICtrlCreateGroup("Postage",                       10,     335,    150,    40)
    GUICtrlCreateGroup("Search Engine Optimisation",    10,     380,    150,    100)
    ;GUI BEHAVIORS
    GUICtrlSetState($GUIArray[1], 1)
    GUISetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $GuiArray[0])
    ;CONTINUING WITH THE SCRIPT
EndFunc
Func _Main()

EndFunc
Func _DataGUI()
    $DataGuiArray[0] =      GUICreate("", @DesktopWidth*0.75, @DesktopHeight*0.75, 0, 0, 0x010F0000)
    $DataGuiArray[1] =      GUICtrlCreateListView("Name|Data", 0, 0, @DesktopWidth, @DesktopHeight)
                            GUICtrlSetResizing($GuiArray[1], '102')
    $DataGuiArray[2] =      GUICtrlCreateListViewItem("Product Name|"&$PName, $GuiArray[1])
    $DataGuiArray[3] =      GUICtrlCreateListViewItem("Product Cost|"&$PCost, $GuiArray[1])
    $DataGuiArray[4] =      GUICtrlCreateListViewItem("Delivery Cost|"&$PDelivery, $GuiArray[1])
    $DataGuiArray[5] =      GUICtrlCreateListViewItem("Description|"&$PDetails, $GuiArray[1])
    $DataGuiArray[6] =      GUICtrlCreateListViewItem("Wholesale|"&$PWholeSale, $GuiArray[1])
    If $PBrand = "" Then
        $DataGuiArray[7] = GUICtrlCreateListViewItem("Brand|BRAND UNKNOWN", $GuiArray[1])
        GUICtrlSetBkColor($DataGuiArray[7], 0xff5040)
    Else
        $DataGuiArray[7] = GUICtrlCreateListViewItem("Brand|"&$PBrand, $DataGuiArray[1])
    EndIf
    $DataGuiArray[8] = GUICtrlCreateListViewItem("Warranty|"&$PWarranty, $DataGuiArray[1])
    GuiSetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $DataGuiArray[0])
    Return
EndFunc
Func _HTMLGetElementByID($html_code, $div_id)
    Local $o_htmlfile = ObjCreate('HTMLFILE')
    If Not IsObj($o_htmlfile) Then
        Return SetError(-1, 0, '')
    EndIf
    $o_htmlfile.open()
    $o_htmlfile.write($html_code)
    $o_htmlfile.close()
    Local $div = $o_htmlfile.getElementByID($div_id)
    If Not IsObj($div) Then
        Return SetError(0, 0, '')
    EndIf
    Return $div.outerHTML
EndFunc
Func _HTMLGetDescription($Desc, $Warranty)
    $Desc = StringStripWS($Desc, 3)
    $Desc = StringReplace($Desc, "<p>", "")
    $Desc = StringReplace($Desc, "</p>", "<br />")
    $Title = StringTrimLeft($Desc, StringInStr($Desc, '<h2>')+3)
    $Title = StringTrimRight($Title, StringLen($Title) - StringInStr($Title, '</h2>')+1)
    $Title = '<div style="text-align: center;"><strong><span style="font-size: 20px; font-family: arial; color: #3333ff;">'&$Title&'</span></strong></div>'
;~   MsgBox(0, "Title", $Title)
    $Desc = StringTrimRight($Desc, (StringLen($Desc) - StringInStr($Desc, "<h4"))+1)
    $Desc = '<span style="font-size: 12px; font-family: arial;"><br />'&StringTrimLeft($Desc, StringInStr($Desc, "<DIV class=clear></DIV>")+24)
    $DescBody = StringLeft($Desc, StringInStr($Desc, '<h3>')-1)
;~   MsgBox(0, "DescBody", $DescBody)
    $Desc = StringTrimLeft($Desc, StringInStr($Desc, '<h3>')-1)
    $Desc = StringReplace($Desc, "<h3>", "<strong>")
    $Desc = StringReplace($Desc, "</h3>", "</strong>")
    $Desc = StringReplace($Desc, '<strong>Product Features</strong>', '<strong>Product Features</strong>')
    $Desc = StringReplace($Desc, '<strong>Features</strong>', '<strong>Product Features</strong>')
    $Desc = StringReplace($Desc, "<strong>Specifications</strong>", "<strong>Product Specifications</strong>")
    $Desc = StringReplace($Desc, "<strong>Contents</strong>", "<strong>Package Contents</strong>")
    $Desc = StringReplace($Desc, "<strong>Package Contains</strong>", "<strong>Package Contents</strong>")
    $Desc = StringReplace($Desc, "<strong>Contains</strong>", "<strong>Package Contents</strong>")
    If $Warranty = "This product comes with a warranty covered by either oo.com.au or the supplier of this product." Then
        $Desc &= "This product comes with a warranty.</span>"
    Else
        $Desc &= $Warranty&"</span>"
    EndIf
    $Desc = StringReplace($Desc, '</li></ul>', '</li>'&@CRLF&'</ul>')
    $DescBody = StringStripWS($DescBody, 7)
    While StringRight($DescBody, 6) = '<br />'
        $DescBody = StringTrimRight($DescBody, 6)
        $DescBody = StringStripWS($DescBody, 7)
    WEnd
    While StringRight($DescBody, 6) = '<br /><br />'
        $DescBody = StringReplace($DescBody, '<br /><br />', '<br />')
        $DescBody = StringStripWS($DescBody, 7)
    WEnd
    $DescBody = StringReplace($DescBody, '<br />', '<br /><br />'&@CRLF)
    $DescArray = StringSplit($Desc, @CR&@LF&@CRLF, 2)
;~   _ArrayDisplay($DescArray)
    $Desc = ""
    For $Repeat = 0 To UBound($DescArray)-1
        $DescArray[$Repeat] = StringStripWS($DescArray[$Repeat], 3)
        If StringLeft($DescArray[$Repeat], 5) = '   <li>' And StringRight($DescArray[$Repeat], 5) <> '</li>' Then
            $DescArray[$Repeat] =  '    '&$DescArray[$Repeat]&'</li>'
        EndIf
        If $DescArray[$Repeat] <> "" Then
            $Desc &= $DescArray[$Repeat]&@CRLF
        EndIf
    Next
;~   MsgBox(0, "DotPoints", $Desc)
    $Title      = StringStripWS($Title, 3)
    $DescBody   = StringStripWS($DescBody, 3)&'<br /><br />'
    $Desc       = StringStripWS($Desc, 3)
    $Desc = StringReplace($Desc, '<li>', '  <li>')
    $Desc = StringReplace($Desc, '</li>', '</li>')
    $Desc = StringReplace($Desc, '<strong>', '<strong>')
    $Desc = StringReplace($Desc, '</strong>', '</strong>')
    $Desc = StringReplace($Desc, '<ul>', '<ul>')
    $Desc = StringReplace($Desc, '</ul>', '</ul>')
    Return $Title&@CRLF&$DescBody&@CRLF&$Desc
EndFunc
Func _HTMLGetProductCode($Desc)
    $Code = StringTrimRight($Desc, StringLen($Desc)-StringInStr($Desc, '</h4>')+1)
    $Code = StringRight($Code, StringLen($Code) - StringInStr($Code, 'Product Code:')-13)
    Return $Code
EndFunc
Func _HTMLGetImages($Images)
    $Images = StringTrimLeft($Images, StringInStr($Images, 'http')-1)
    Local $ImagesString = StringLeft($Images, StringInStr($Images, '.jpg')+3)&'|'
    While StringLeft($Images, StringInStr($Images, '.jpg')+3) <> StringRight($ImagesString, StringLen($ImagesString) - StringInStr($ImagesString, '|', 0, 1))&'|'
        If StringInStr($Images, 'http', 0, 2)-1 = '-1' Then
            ExitLoop
        EndIf
        $Images = StringTrimLeft($Images, StringInStr($Images, 'http', 0, 2)-1)
        $ImagesString &= StringLeft($Images, StringInStr($Images, '.jpg')+3)&'|'
    WEnd
    $ImagesString = StringTrimRight($ImagesString, 1)
;~   MsgBox(0,"", $Images)
;~   MsgBox(0,"Images",$ImagesString)
    Return $ImagesString
EndFunc
Func _HTMLGetBrand($Desc)
    Local $Brand = ""
    If StringInStr($Desc, '<div class="brand">') Then
        $Brand = StringTrimRight(StringTrimLeft($Desc, StringInStr($Desc, '<div class="brand">')-1), StringLen($Desc) - StringInStr($Desc, "</a>", 0, 2)+1)
        $Brand = StringRight($Brand, StringLen($Brand) - StringInStr($Brand, "More ")-4)
    ElseIf StringInStr($Desc, '<div class=brand>') Then
        $Brand = StringTrimRight(StringTrimLeft($Desc, StringInStr($Desc, '<div class=brand>')-1), StringLen($Desc) - StringInStr($Desc, "</a>", 0, 2)+1)
        $Brand = StringRight($Brand, StringLen($Brand) - StringInStr($Brand, "More ")-4)
    ElseIf StringInStr($Desc, 'Brand: ') Then
        $Brand = StringTrimLeft($Desc, StringInStr($Desc, 'Brand: ')+6)
        $Brand = StringLeft($Brand, StringInStr($Brand, '</li>')-1)
    EndIf
    Return $Brand
EndFunc
Func _HTMLGetWarranty($Warranty)
    $Warranty = StringTrimLeft(StringTrimRight($Warranty, StringLen($Warranty) - StringInStr($Warranty, '</p>')+1), StringInStr($Warranty, '<p>')+2)
    If $Warranty = 'This product comes with a warranty covered by either oo.com.au or the supplier of this product.' Then
        $Warranty = 'This product comes with a warranty.'
    EndIf
    Return $Warranty
EndFunc
Func _HTMLGetCost($Main)
    If StringInStr($Main, '<P class=was>') Then
        $Cost = StringTrimRight(StringTrimLeft($Main, StringInStr($Main, '<P class=was>')+24), StringLen(StringTrimLeft($Main, StringInStr($Main, '<P class=was>')+24))-StringInStr(StringTrimLeft($Main, StringInStr($Main, '<P class=was>')+24), '</span>')+1)
    Else
        $Cost = StringTrimLeft(StringTrimRight($Main, StringLen($Main)-StringInStr($Main, "</strong>")+1), StringInStr($Main, "<P class=price>Our Price: <strong>")+34)
    EndIf
    Return $Cost
EndFunc
Func _Images()
    Local $Image, $Width, $Height
;~  _ArrayDisplay($PImagesArray)
    $ImagesGuiArray[0]  =   GUICreate("Images", 600, 680)
                            GUISetBkColor(0xd0d0d0, $ImagesGuiArray[0])
    $ImagesGuiArray[1]  =   GUICtrlCreateButton("<", 245, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[1], '_PrevImage')
    $ImagesGuiArray[2]  =   GUICtrlCreateButton("Edit", 285, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[2], '_EditImage')
    $ImagesGuiArray[3]  =   GUICtrlCreateButton(">", 325, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[3], '_NextImage')
    $ImagesGuiArray[4]  =   GUICtrlCreateLabel("", 245, 645, 105, 30, 0x01)
    GUICtrlSetState($ImagesGuiArray[1], 128)
    If UBound($PImagesArray) = 1 Then
        GUICtrlSetState($ImagesGuiArray[3], 128)
    EndIf
    If UBound($PImagesArray)>8 Then
        $PImagesArrayLimit = 8
    Else
        $PImagesArrayLimit = UBound($PImagesArray)-1
    EndIf
    _CreateImage()
    GUISetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $ImagesGuiArray[0])
    Return
EndFunc
Func _CreateImage()
    If StringLeft($PImagesArray[0], 4) = 'http' Then
        InetGet($PImagesArray[0], @TempDir&"Pic.jpg", 16, 0)
    Else
        FileWrite(@TempDir&"Pic.jpg", FileRead($ImagesDirectory&""&$PNum&" 0.jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Width = 600
    ElseIf $Height > $Width Then
        $Width = 600*($Height/$Width)
        $Height = 600
    Else
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    $Pic = GUICtrlCreatePic(@TempDir&"Pic.jpg", 0, 0, $Width, $Height)
    $ThisImage = 0
    GUICtrlSetData($ImagesGuiArray[4], "Image 1 of "&UBound($PImagesArray))
    Return
EndFunc
Func _NextImage()
    GUICtrlSetState($ImagesGuiArray[1], 255)
    $ThisImage += 1
    GUICtrlSetData($ImagesGuiArray[4], "Image "&$ThisImage&" of "&UBound($PImagesArray))
    If StringLeft($PImagesArray[$ThisImage], 4) = 'http' Then
        InetGet($PImagesArray[$ThisImage], @TempDir&"Pic.jpg", 16, 0)
    Else
        FileDelete(@TempDir&"Pic.jpg")
        FileWrite(@TempDir&"Pic.jpg", FileRead($ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    GUICtrlDelete($Pic)
    $Pic = GUICtrlCreatePic(@TempDir&"Pic.jpg", $Left, $Top, $Width, $Height)
    If $ThisImage = UBound($PImagesArray)-1 Then
        GUICtrlSetState($ImagesGuiArray[3], 128)
    EndIf
    Return
EndFunc
Func _EditImage()
    Local $Label, $ImageURL
    GUICtrlDelete($Pic)
    $Label = GUICtrlCreateLabel("Waiting for Microsoft Paint to close.", 220, 290)
    RunWait("mspaint "&@TempDir&"Pic.jpg", @TempDir, @SW_SHOW)
    $PImagesArray[$ThisImage] = $ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg"
    FileDelete($ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg")
    FileWrite($ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg", FileRead(@TempDir&"Pic.jpg"))
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    $Pic = GUICtrlCreatePic(@TempDir&"Pic.jpg", $Left, $Top, $Width, $Height)
    GUICtrlDelete($Label)
    Return
EndFunc
Func _PrevImage()
    GUICtrlSetState($ImagesGuiArray[3], 255)
    $ThisImage -= 1
    GUICtrlSetData($ImagesGuiArray[4], "Image "&$ThisImage&" of "&UBound($PImagesArray))
    If StringInStr($PImagesArray[$ThisImage], 'http') Then
        InetGet($PImagesArray[$ThisImage], @TempDir&"Pic.jpg", 16, 0)
    Else
        FileDelete(@TempDir&"Pic.jpg")
        FileWrite(@TempDir&"Pic.jpg", FileRead($ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    GUICtrlDelete($Pic)
    $Pic = GUICtrlCreatePic(@TempDir&"Pic.jpg", $Left, $Top, $Width, $Height)
    If $ThisImage = 0 Then
        GUICtrlSetState($ImagesGuiArray[1], 128)
    EndIf
    Return
EndFunc
Func _Price($FinalPrice)
    $FinalPrice = 1.3*$FinalPrice
    If $FinalPrice > 15 Then
        Local $FinalPriceArray = StringSplit($FinalPrice, ".", 3)
        If UBound($FinalPriceArray) = 1 Then
            _ArrayAdd($FinalPriceArray, 0)
        EndIf
        If StringRight($FinalPriceArray[0], 1) & "." & $FinalPriceArray[1] >= 2.45 And StringRight($FinalPriceArray[0], 1) & "." & $FinalPriceArray[1] < 7.45 Then
            $FinalPrice = StringLeft($FinalPriceArray[0], StringLen($FinalPriceArray[0])-1)&"4.95"
        Else
            If StringRight($FinalPriceArray[0], 1) > 5 Then
                $FinalPrice = StringLeft($FinalPriceArray[0], StringLen($FinalPriceArray[0])-1)&"9.95"
            Else
                $FinalPrice = (StringLeft($FinalPriceArray[0], StringLen($FinalPriceArray[0])-1)&"9.95")-10
            EndIf
        EndIf
    EndIf
;~  MsgBox(0,"",$FinalPrice)
    Return $FinalPrice
EndFunc
Func _GetSearchTags($SearchTags)
    Local $DontAllow[4] = [" ", ",", "-", "&amp"]
    For $Repeat = 0 To UBound($DontAllow)-1
        $SearchTags = StringReplace($SearchTags, $DontAllow[$Repeat], "|")
    Next
    While StringInStr($SearchTags, "||")
        $SearchTags = StringReplace($SearchTags, "||", "|")
    WEnd
    Return $SearchTags
EndFunc
Func _GetSEOKeywords($Keywords)
    Local $DontAllow[4] = [" ", ",", "-", "&amp"]
    For $Repeat = 0 To UBound($DontAllow)-1
        $Keywords = StringReplace($Keywords, $DontAllow[$Repeat], ",")
    Next
    While StringInStr($Keywords, ",,")
        $Keywords = StringReplace($Keywords, ",,", ",")
    WEnd
    Return $Keywords
EndFunc
Func _Exit()
    Switch @GUI_WinHandle
        Case $GuiArray[0]
            Exit
        Case $ImagesGuiArray[0]
            GUIDelete($ImagesGuiArray[0])
            $ImagesGuiArray[0] = -1
            _CreateGUI()
        Case $ProdNumGuiArray[0]
            $Exit = MsgBox(4,"Exit Now?", "Are you sure you want to exit?")
            If $Exit = 6 Then
                Exit
            Else
                Return
            EndIf
        Case Else
            GUIDelete(@GUI_WinHandle)
            ;DataGuiArray[0]
    EndSwitch
    Return
EndFunc
Func _OnExit()
    GUIDelete($GuiArray[0])
    _GDIPlus_Shutdown()
EndFunc
Func _Delivery($Main)
    Local $Delivery
    ;$Delivery =    StringTrimLeft($PMain, StringInStr($PMain, '<p class=delivery>', 0)+36)
    ;$Delivery = StringTrimRight(StringTrimLeft($Delivery, StringInStr($Delivery, "$")-1), StringLen($Delivery)-StringInStr($Delivery, ".")-2)
    Local $Delivery = StringRegExp($Main, '<P class=delivery>([Ss]*?)</P>', 1)
    $Delivery = StringRegExp($Delivery[0], '<STRONG>([S]+)</STRONG>', 1)
    $Delivery[0] = StringTrimLeft($Delivery[0], 1)
;~   MsgBox(0,"",$Delivery[0])
    Return $Delivery[0]
EndFunc
Func _GetSEODescription($Desc2)
    $Desc2 = _HTML2PlainText($Desc2);StringRegExpReplace($Desc2, "(<[^>]+?>)", "")
    $Desc2 = _RemExtraLineBreaks($Desc2);StringReplace($Desc2, @CRLF&@CRLF, @CRLF, 0)
    Return $Desc2
EndFunc
Func _HTML2PlainText($sHtml)
    $sHtml = StringRegExpReplace($sHtml, "<br[^>]*/>", @CRLF)
    $sHtml = StringRegExpReplace($sHtml, "</?p[^>]*>", @CRLF & @CRLF)
    $sHtml = StringRegExpReplace($sHtml, '(<[^>]+>)', '')
    Return $sHtml
EndFunc
Func _RemExtraLineBreaks($sTxt)
    $sTxt = StringRegExpReplace($sTxt, "[s][s]+", @CRLF)
    Return $sTxt
EndFunc
Func _IsURL($URL)
    Select
        Case StringInStr($URL, ".com")
            Return True
        Case StringInStr($URL, ".net")
            Return True
        Case StringInStr($URL, ".org")
            Return True
        Case StringInStr($URL, ".gov")
            Return True
        Case StringInStr($URL, ".edu")
            Return True
        Case StringInStr($URL, ".biz")
            Return True
        Case Else
            Return False
    EndSelect
EndFunc
Func _Restart()
    GUIDelete($GuIArray[0])
    _Start()
EndFunc

But now it won't download the file, even though it is running the InetGet function.

Oh, just saw your last comment. I will get rid of all of the extra processing and such like, and then I'll get back to you.

Edited by Mikeman27294
Link to comment
Share on other sites

While 1
    WEnd

Learn to use Sleep() before you burn something up! :)

Ok. I just thought people do that for the sake of having something in their while loops?

Anyway, now that I have stripped all processing from it, I have ended up with this:

#AutoIt3Wrapper_UseX64=N
#include <Array.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <Misc.au3>
#include <String.au3>
Opt("GUIOnEventMode", 1)
Opt("GUICloseOnEsc", 0)
Opt("TrayAutoPause", 0)
_GDIPlus_Startup()
OnAutoItExitRegister('_OnExit')
Global $PImagesArray[3] = ['http://img4.oo.com.au/prod/ELSLIM59PNK/1b.jpg', 'http://img4.oo.com.au/prod/ELSLIM59PNK/2b.jpg', 'http://img4.oo.com.au/prod/ELSLIM59PNK/3b.jpg']
Global $TestGui = 0, $DataGuiArray[10], $ProdNumGuiArray[6], $GUIArray[18], $Selected, $FilePath, $File, $Product, $PInfo, $PWarranty, $PDetails, $PCode, $PWrap, $PMain, $PName, $PCost, $PImages, $ImagesString, $Repeat, $PDetails, $PBrand, $PDelivery, $PWholeSale, $PSearchTags, $PWholesale, $SEOKeywords, $SEODesc, $PNum = "NO PRODUCT NUMBER", $PNumLimit, $MichaelBot = "MichaelBot/1.0 (+http://http://www.Michaelonline.com.au/)", $ThisImage = 0, $Pic, $ImagesGuiArray[5], $ImagesDirectory = "C:Users"&@UserName&"DesktopImages", $PImagesArray
Global $UsePNum = 0, $Mode = 0
_Images()
While $ImagesGuiArray[0] <> -1
Sleep(100)
WEnd
While 1
For $Repeat = 1 To 16 ;Getting selected radio box
If GUICtrlRead($GuiArray[$Repeat]) = 1 Then
;    MsgBox(0,"",$Selected)
$Selected = $Repeat
ExitLoop
EndIf
Next
Switch $Selected
Case 1 ;Product Name
ClipPut($PName)
While GUICtrlRead($GuiArray[1]) = 1
;~                 If _IsPressed(11) And _IsPressed(56) Then
;~                     GUICtrlSetState($GuiArray[3], $GUI_CHECKED)
;~                 EndIf
WEnd
Case 2 ;Product Code
ClipPut($PNum)
While GUICtrlRead($GuiArray[2]) = 1
If _IsPressed(11) And _IsPressed(56) Then
While _IsPressed(11) And _IsPressed(56)
WEnd
Sleep(100)
Send("{TAB}")
Send("10")
EndIf
WEnd
Case 3 ;Product Cost
ClipPut($PCost)
While GUICtrlRead($GuiArray[3]) = 1
WEnd
Case 4 ;Product Description
ClipPut($PDetails)
While GUICtrlRead($GuiArray[4]) = 1
WEnd
Case 5 ;Images
ClipPut($PImagesArray[0])
$ThisImage = 0
While GUICtrlRead($GuiArray[5]) = 1
If _IsPressed(11) And _IsPressed(56) Then
$ThisImage += 1
If $ThisImage = UBound($PImagesArray) Then
ClipPut("")
Else
ClipPut($PImagesArray[$ThisImage])
EndIf
EndIf
WEnd
Case 6 ;Wholesale
ClipPut($PWholeSale)
While GUICtrlRead($GuiArray[6]) = 1
WEnd
Case 7 ;Brand
ClipPut($PBrand)
While GUICtrlRead($GuiArray[7]) = 1
WEnd
Case 8 ;Notes
ClipPut('Product Code: '&$PCode)
While GUICtrlRead($GuiArray[8]) = 1
WEnd
Case 9 ;Product Search Tags
ClipPut(StringLeft($PSearchTags, StringInStr($PSearchTags, "|", 0, 1)-1))
$ThisPSearchTags = $PSearchTags
While GUICtrlRead($GuiArray[9]) = 1
If _IsPressed(11) And _IsPressed(56) Then
Sleep(100)
$ThisPSearchTags = StringTrimLeft($ThisPSearchTags, StringInStr($ThisPSearchTags, "|"))
ClipPut(StringLeft($ThisPSearchTags, StringInStr($ThisPSearchTags, "|")-1))
While _IsPressed(11) And _IsPressed(56)
WEnd
EndIf
If ClipGet() = '' Then
While GUICtrlRead($GuiArray[9]) = 1
WEnd
EndIf
WEnd
Case 10 ;Product Identifyer
ClipPut($PCode)
While GUICtrlRead($GuiArray[10]) = 1
WEnd
Case 11 ;Fixed Cost Postage
ClipPut($PDelivery)
While GUICtrlRead($GuiArray[10]) = 1
WEnd
Case 12 ;SEO Title
ClipPut($PName)
While GUICtrlRead($GuiArray[11]) = 1
WEnd
Case 13 ;SEO Keywords
ClipPut($SEOKeywords)
While GUICtrlRead($GuiArray[12]) = 1
WEnd
Case 14 ;SEO Description
ClipPut($SEODesc)
While GUICtrlRead($GuiArray[13]) = 1
WEnd
Case 15 ;Custom URL
ClipPut($PNum)
While GUICtrlRead($GuiArray[14]) = 1
WEnd
EndSwitch
WEnd
Func _CreateGUI()
    ;GUI WINDOW
    $GUIArray[0] =        GUICreate("          ", 170, 545, @DesktopWidth-200, 75)
                        WinSetOnTop($GuiArray[0], "", 1)
    ;BASIC DETAILS
    $GUIArray[1] =        GUICtrlCreateRadio("Product Name", 22, 25)
    $GUIArray[2] =        GUICtrlCreateRadio("Product Code", 22, 45)
    ;PRICE DETAILS
    $GUIArray[3] =        GUICtrlCreateRadio("Final Price", 22, 90)
    ;DESCRIPTION
    $GUIArray[4] =        GUICtrlCreateRadio("Description", 22, 135)
    ;IMAGES
    $GUIArray[5] =        GUICtrlCreateRadio("Images", 22, 180) ;Copies the image URL into an array
    ;ADVANCED DETAILS
    $GUIArray[6] =        GUICtrlCreateRadio("Wholesale Price", 22, 225)
    $GUIArray[7] =        GUICtrlCreateRadio("Brand", 22, 245)
    $GUIArray[8] =        GUICtrlCreateRadio("Notes", 22, 265)
    $GUIArray[9] =        GUICtrlCreateRadio("Product Search Tags", 22, 285)
    $GuiArray[10] =        GUICtrlCreateRadio("Product Identifiers", 22, 305)
    ;POSTAGE
    $GUIArray[11] =        GUICtrlCreateRadio("Fixed Cost", 22, 350)
    ;SEARCH ENGINE OPTIMISATION
    $GUIArray[12] =        GUICtrlCreateRadio("Title", 22, 395)
    $GUIArray[13] =        GUICtrlCreateRadio("Keywords", 22, 415)
    $GUIArray[14] =        GUICtrlCreateRadio("Description", 22, 435)
    $GUIArray[15] =        GUICtrlCreateRadio("Custom URL", 22, 455)
    ;BUTTONS
    $GUIArray[16] =        GUICtrlCreateButton("New Product", 10, 490, 150, 22)
                        GUICtrlSetOnEvent($GuiArray[16], "_Restart")
    ;STATUSBAR
    $GuiArray[17] =        _GUICtrlStatusBar_Create($GuiArray[0])
                        _GUICtrlStatusBar_SetText($GuiArray[17], $PNum)
    ;GROUPS
    GUICtrlCreateGroup("Basic Details",                    10,        10,        150,    60)
    GUICtrlCreateGroup("Price Details",                    10,        75,        150,    40)
    GUICtrlCreateGroup("Description",                     10,        120,    150,    40)
    GUICtrlCreateGroup("Images",                        10,        165,    150,    40)
    GUICtrlCreateGroup("Advanced Details",                10,        210,    150,    120)
    GUICtrlCreateGroup("Postage",                        10,        335,    150,    40)
    GUICtrlCreateGroup("Search Engine Optimisation",    10,        380,    150,    100)
    ;GUI BEHAVIORS
    GUICtrlSetState($GUIArray[1], 1)
    GUISetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $GuiArray[0])
    ;CONTINUING WITH THE SCRIPT
EndFunc
Func _Images()
    Local $Image, $Width, $Height
;~    _ArrayDisplay($PImagesArray)
    $ImagesGuiArray[0]    =    GUICreate("Images", 600, 680)
                            GUISetBkColor(0xd0d0d0, $ImagesGuiArray[0])
    $ImagesGuiArray[1]    =    GUICtrlCreateButton("<", 245, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[1], '_PrevImage')
    $ImagesGuiArray[2]    =    GUICtrlCreateButton("Edit", 285, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[2], '_EditImage')
    $ImagesGuiArray[3]    =    GUICtrlCreateButton(">", 325, 610, 30, 30)
                            GUICtrlSetOnEvent($ImagesGuiArray[3], '_NextImage')
    $ImagesGuiArray[4]    =    GUICtrlCreateLabel("", 245, 645, 105, 30, 0x01)
    GUICtrlSetState($ImagesGuiArray[1], 128)
    If UBound($PImagesArray) = 1 Then
        GUICtrlSetState($ImagesGuiArray[3], 128)
    EndIf
    If UBound($PImagesArray)>8 Then
        $PImagesArrayLimit = 8
    Else
        $PImagesArrayLimit = UBound($PImagesArray)-1
    EndIf
    _CreateImage()
    GUISetOnEvent(-3, "_Exit")
    GUISetState(@SW_SHOW, $ImagesGuiArray[0])
    Return
EndFunc
Func _CreateImage()
    If StringLeft($PImagesArray[0], 4) = 'http' Then
        InetGet($PImagesArray[0], @TempDir&"Pic.jpg", 16, 0)
    Else
        FileWrite(@TempDir&"Pic.jpg", FileRead($ImagesDirectory&""&$PNum&" 0.jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Width = 600
    ElseIf $Height > $Width Then
        $Width = 600*($Height/$Width)
        $Height = 600
    Else
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    $Pic = GUICtrlCreatePic(@TempDir&"Pic.jpg", 0, 0, $Width, $Height)
    $ThisImage = 0
    GUICtrlSetData($ImagesGuiArray[4], "Image 1 of "&UBound($PImagesArray))
    Return
EndFunc
Func _NextImage()
    GUICtrlSetState($ImagesGuiArray[1], 255)
    $ThisImage += 1
    GUICtrlSetData($ImagesGuiArray[4], "Image "&$ThisImage+1&" of "&UBound($PImagesArray))
    If StringLeft($PImagesArray[$ThisImage], 4) = 'http' Then
        InetGet($PImagesArray[$ThisImage], @TempDir&"Pic.jpg", 16, 0)
    Else
        FileDelete(@TempDir&"Pic.jpg")
        FileWrite(@TempDir&"Pic.jpg", FileRead($ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    GUICtrlDelete($Pic)
    $Pic = GUICtrlCreatePic(@TempDir&"Pic.jpg", $Left, $Top, $Width, $Height)
    If $ThisImage = UBound($PImagesArray)-1 Then
        GUICtrlSetState($ImagesGuiArray[3], 128)
    EndIf
    Return
EndFunc
Func _EditImage()
    Local $Label, $ImageURL
    GUICtrlDelete($Pic)
    $Label = GUICtrlCreateLabel("Waiting for Microsoft Paint to close.", 220, 290)
    RunWait("mspaint "&@TempDir&"Pic.jpg", @TempDir, @SW_SHOW)
    $PImagesArray[$ThisImage] = $ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg"
    FileDelete($ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg")
    FileWrite($ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg", FileRead(@TempDir&"Pic.jpg"))
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    $Pic = GUICtrlCreatePic(@TempDir&"Pic.jpg", $Left, $Top, $Width, $Height)
    GUICtrlDelete($Label)
    Return
EndFunc
Func _PrevImage()
    GUICtrlSetState($ImagesGuiArray[3], 255)
    $ThisImage -= 1
    GUICtrlSetData($ImagesGuiArray[4], "Image "&$ThisImage+1&" of "&UBound($PImagesArray))
    If StringInStr($PImagesArray[$ThisImage], 'http') Then
        InetGet($PImagesArray[$ThisImage], @TempDir&"Pic.jpg", 16, 0)
    Else
        FileDelete(@TempDir&"Pic.jpg")
        FileWrite(@TempDir&"Pic.jpg", FileRead($ImagesDirectory&""&$PNum&" "&$ThisImage&".jpg"))
    EndIf
    $Image = _GDIPlus_ImageLoadFromFile(@TempDir&"Pic.jpg")
    $Width = _GDIPlus_ImageGetWidth($Image)
    $Height = _GDIPlus_ImageGetHeight($Image)
    If $Width > $Height Then
        $Height = 600*($Height/$Width)
        $Top = 300 - (0.5*$Height)
        $Width = 600
        $Left = 0
    ElseIf $Height > $Width Then
        $Width = 600*($Width/$Height)
        $Left = 300 - (0.5*$Width)
        $Height = 600
        $Top = 0
    Else
        $Left = 0
        $Top = 0
        $Height = 600
        $Width = 600
    EndIf
    _GDIPlus_ImageDispose($Image)
    GUICtrlDelete($Pic)
    $Pic = GUICtrlCreatePic(@TempDir&"Pic.jpg", $Left, $Top, $Width, $Height)
    If $ThisImage = 0 Then
        GUICtrlSetState($ImagesGuiArray[1], 128)
    EndIf
    Return
EndFunc
Func _Exit()
    Switch @GUI_WinHandle
        Case $GuiArray[0]
            Exit
        Case $ImagesGuiArray[0]
            GUIDelete($ImagesGuiArray[0])
            $ImagesGuiArray[0] = -1
            _CreateGUI()
        Case $ProdNumGuiArray[0]
            $Exit = MsgBox(4,"Exit Now?", "Are you sure you want to exit?")
            If $Exit = 6 Then
                Exit
            Else
                Return
            EndIf
        Case Else
            GUIDelete(@GUI_WinHandle)
            ;DataGuiArray[0]
    EndSwitch
    Return
EndFunc
Func _OnExit()
    GUIDelete($GuiArray[0])
    _GDIPlus_Shutdown()
EndFunc
Func _Restart()
Run ("""" & @AutoitEXE & """ """ & @ScriptFullPath & """")
Exit
EndFunc

This actually works though and I didn't touch the GUIEventMode or anything, just moved the while loop (which also does work in a function, I just tested it for the sake of curiosity), and edited the restart function. Otherwise, no changes made. :S I don't know what was happening now.

Edited by Mikeman27294
Link to comment
Share on other sites

  • Moderators

Mikeman27294,

I was going to mention your empty loops later. You need a Sleep in there to give the CPU a bit of idle time or it will overheat. :)

As the smallest Sleep value you can get with AutoIt is 10ms, just put a Sleep(10) in there. You do NOT need to do this if you have a GUIGetMsg or TrayGetMsg function in the loop - they automatically give the CPU a break. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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

×
×
  • Create New...