Jump to content

Recommended Posts

Posted

Hello everyone

Today i got back to making simple (and slow) AutoIT scripts, but as always, i find a problem that i can't really seem to resolve by myself, and would like someone more talented than me to help me.

So here is the problem:

I'm trying to get a date that the user put in a DateBox (i don't really know the name of this thing, but it's created by using GUICtrlCreateDate), in a specific format (yyyyMMdd, WITHOUT THE SLASH).

I tried using the GuiCtrlSendMsg but it only works one time...

I am out of ideas so here is the script

#include <GuiConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")


Global $LABEL, $EDIT, $ARCHIVE, $VIEW, $DATE, $iMsg, $sData, $Website, $Style, $Date

; Create the GUI window and controls
GUICreate("WayBack Machine Archiver", 350, 200,  (@DesktopWidth - 350) / 2, (@DesktopHeight - 200) / 2)
$DATE = GUICtrlCreateDate("", 225, 13, 100, 20, $DTS_SHORTDATEFORMAT)
$LABEL = GUICtrlCreateLabel("Enter Website URL in the feild below", 30, 15, 300, 45)
$EDIT = GUICtrlCreateEdit("www.example.com", 30, 60, 300, 21, $ES_NOHIDESEL)
$ARCHIVE = GUICtrlCreateButton("Archive Website", 200, 95, 120, 30)
$VIEW = GUICtrlCreateButton("View Archive", 37, 95, 125, 30)
GUICtrlSendMsg($DATE, $DTM_SETFORMATW, 1, "yyyyMMdd")

; Run the GUI until it is closed
GUISetState()


While 1
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            ExitLoop
            ;When button is pressed, label text is changed
            ;to combobox value
        Case $iMsg = $ARCHIVE
            $Website = GUICtrlRead($EDIT)
            GUICtrlSetData($LABEL, "Archiving Website : " & $Website & "...")
            $oHTTP.Open("GET", "https://web.archive.org/save/" & $Website)

            $oHTTP.Send()
            $oReceived = $oHTTP.ResponseText
            if @error Then
                MsgBox(0,"error", ":(") 
            EndIf
            $oStatusCode = $oHTTP.Status
            if @error Then
                MsgBox(0,"error", ":(") 
            EndIf   
            
            If Not $oStatusCode == 200 Then
;~              MsgBox (0, "Archiving failed !", "Archiving failed, I don't know much more...")
            Else
                ShellExecute("https://web.archive.org/web/" & $Website)
                GUICtrlSetData($LABEL, "Done !")
            EndIf
            
        Case $iMsg = $VIEW              
            $Website = GUICtrlRead($EDIT)
            $Date = GUICtrlRead($DATE)
            ShellExecute ("https://web.archive.org/web/" & $Date & "/" & $Website )

;~      Case $iMsg = $DATE
;~          $Website = GUICtrlRead($EDIT)
;~          $Date = GUICtrlRead($DATE) ;NOT WORKING :((
    EndSelect
WEnd

Thanks again !

😀

 

  • Solution
Posted

I just skimmed the script (time for me to go to bed 😴) , but one point caught my eye.
You use the variables $DATE (for the controlID) and $Date (for the date). Since AutoIt is not case sensitive on variable names, this can cause problems.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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
  • Recently Browsing   0 members

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