Sign in to follow this  
Followers 0
Mikeman27294

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

13 posts in this topic

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.

Share this post


Link to post
Share on other sites



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


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

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.

Share this post


Link to post
Share on other sites

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


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

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.

Share this post


Link to post
Share on other sites

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


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

Oh, ok thanks.

Sorry I didn't fully understand that. It's odd though because it was working earlier when the while loop was in a function. Anyway, I will try that out then, and return here if it still doesn't work.

Share this post


Link to post
Share on other sites

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


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

#9 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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


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

Ok, thanks. I was aware that people do that in their scripts too, but I believed that since there is no heavy processing in an empty while loop, it wouldn't matter. Anyway, thanks for letting me know about that.

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  
Followers 0

  • Similar Content

    • Eggsplorer
      By Eggsplorer
      Hi,
      Ich hab ein Script für Windows Updates, dass nach dem OOBE aufgerufen werden soll. Run/RunOnce ist daher nicht möglich.
      Stattdessen möchte ich das Script in den Autostart schreiben lasse. Wenn die OOBE beendet wird und der Administrator angemeldet wird, soll das Update-Script einmalig aufgerufen werden und sich anschl. selbst löschen.
      Lang rede, kurzer Sinn:
      Wie kann ich folgendes Script in den Autostart schreiben?
      RunWait(@ComSpec & " /c " & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\UA\Scripts\win-updates.ps1 -MaxUpdatesPerCycle 100 -RestartRequired 1", "") Ich würde ungern eine BAT oder EXE reinkopieren, da ich es unsauber finde. Die müsste ja auch zusätzlich irgendwo liegen.
      Danke
      Eggsplorer
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I worked a bit on a little project of mine, and I managed to do what I was trying to do, or, automate a quiz in AutoIt.
      Now, everything works fine but, in order to achieve what I'm trying to achive, I'd like to make this script run faster.
      I'll attach a portion of the code in order to let you understand what my script does.
      $objIE_h1 = _IETagNameGetCollection($objIE, "h1") ; Take the text of the answer If @error Then ConsoleWrite("Errore durante la lettura degli h1 nella pagina. - Errore: " & @error & @CRLF) Else For $objElement In $objIE_h1 $strInnerText = $objElement.innerText Next Select Case StringInStr($strInnerText, "QUESTION") ; Here is the question ; PS4 PRO $objSpans = _IETagNameGetCollection($objIE, "span") ; Answers are stored here For $objElement In $objSpans If $i >= 4 Then $strAnswer = $objElement.innerText ; Take the text of the answer n° 0, 1, 2, 3 If StringInStr($strAnswer, "CORRECT ANSWER") Then ; If I match the correct answer, then, I have to click on the input with answer id = answer_i $j = $i - 4 $objInput = _IEGetObjById($objIE, "answer_" & $j) If @error Then ConsoleWrite("Errore durante la lettura della risposta #" & $i & " - Errore: " & @error & @CRLF) Else _IEAction($objInput, "click") If @error Then ConsoleWrite("Errore durante il click sull'elemento. - Errore: " & @error) Else ConsoleWrite($j & ") Risposta: " & $strAnswer & @CRLF) ExitLoop EndIf EndIf EndIf $i+=1 Else $i+=1 EndIf Next $i = 0 $j = 0 This is what my script does.
      Questions are 20, in which I have 15 multiple choice question, 2 images ( on which I use _IEImgClick() ), and 3 text inputs ( a simple send with the text I have to enter ).
      How can I make all of these, faster?
      If I reach this goal, I've probably done one of my best goals in life, and I'd like to share my happiness with you, giving a huge donation to this fantastic community!
      Thanks for your help
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I want create retractable bar using autoit
      I tried creating slider, but there's a problem with screen reader for the blind, so is there another retractable tape?
      It is advisable to not accept dragging with the keybord only with  mouse
      note:
      This bar is needed in the process of raising and lowering the volume
      I hope that there is a solution to do that
      i waiting your responses.
      Thanks in advance to all members and administrators
    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it