Jump to content

GUI Button Not Working


Sarne
 Share

Recommended Posts

Hi All,

This is the first time I've had to post a question, I've always found my answers just simply trolling the forums. I'm just frustrated and tired over this one so I hope someone can help.

When I click the ABORT button, nothing happens & the download continues.

I apologize, but I had to replace quite a bit of the code due to liability reasons.

One last thing, does my code look convoluted? Are there easier ways to go about what I've done?

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.10.0
 Author:         

 Script Function:
    Burn Client ISO

#ce ----------------------------------------------------------------------------
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <UpDownConstants.au3>

GuiCreate("COMPANY ISO Burner", 250, 300)
;GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

GUICtrlCreateLabel("Please select your client from the list.",5,5)
$client = GUICtrlCreateList("", 5, 20, 100, 100)
GuiCtrlSetData(-1, "CLIENT1|CLIENT2|CLIENT3|CLIENT4|CLIENT4|CLIENT5", "")

GuiCtrlCreateLabel("Please enter your Agent ID", 5, 125)
$AgentID = GuiCtrlCreateInput("111301", 5, 140, 70, 20)
GuiCtrlCreateUpDown(-1)

$progress = GUICtrlCreateProgress( 5, 175, 200, 10 )

$button_submit = GUICtrlCreateButton("SUBMIT", 175, 250, 60)
$button_close = GUICtrlCreateButton("CLOSE", 5, 250, 60)
$button_abort = GUICtrlCreateButton("ABORT", 175, 220, 60)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $button_submit
            If GUICtrlRead($client) = "CLIENT1" Then
                $clientDir = "CLIENT1"
                $ClientFile = "Client1"
                $filename = "c:\COMPANY\"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v1.0.4.iso"
                $URL = "http://example.com/lx_upload/"&$clientDir&"/"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v1.0.4.iso"
            
            ElseIf GUICtrlRead($client) = "CLIENT2" Then
                $clientDir = "CLIENT2"
                $ClientFile = "aiz"
                $filename = "c:\COMPANY\"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v1.0.2.iso"
                $URL = "http://example.com/lx_upload/"&$clientDir&"/"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v1.0.2.iso"
            
            ElseIf GUICtrlRead($client) = "CLIENT3" Then
                $clientDir = "CLIENT3"
                $ClientFile = "Client3"
                $filename = "c:\COMPANY\"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v1.0.4.iso"
                $URL = "http://example.com/lx_upload/"&$clientDir&"/"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v1.0.4.iso"
            
            ElseIf GUICtrlRead($client) = "CLIENT4" Then
                $clientDir = "CLIENT4"
                $ClientFile = "Client4"
                $filename = "c:\COMPANY\"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v5.0.4.iso"
                $URL = "http://example.com/lx_upload/"&$clientDir&"/"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v5.0.4.iso"
            
            ElseIf GUICtrlRead($client) = "CLIENT4" Then
                $clientDir = "CLIENT4"
                $ClientFile = "Client4"
                $filename = "c:\COMPANY\"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v5.0.4.iso"
                $URL = "http://example.com/lx_upload/"&$clientDir&"/"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v5.0.4.iso"
            
            ElseIf GUICtrlRead($client) = "CLIENT5" Then
                $clientDir = "CLIENT5"
                $clientFile = "Client5"
                $filename = "c:\COMPANY\"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v1.0.1.iso"
                $URL = "http://example.com/lx_upload/"&$clientDir&"/"&$clientFile&"_"&GUICtrlRead($AgentID)&"-v1.0.1.iso"
            EndIf
        ;MsgBox(0,"Filename Location",$filename)
        ;MsgBox(0,"Test Input URL", $URL)
            $Download = InetGet($URL,$filename,0,1)
            
            $dlsize = InetGetSize( $URL )
            
            GUISetState()
            While @InetGetActive
                If $nMsg = $button_abort Then
                    InetGet("abort")
                    MsgBox(0,"Download Aborted", "Your Download has been successfully aborted")
                EndIf
            Sleep(1000)
            GUICtrlSetData($progress, Int((@Inetgetbytesread / $dlsize) *100))
            ;GUICtrlCreateLabel( Int(@InetGetBytesRead / 1000) & " Kb / " & Int($dlsize / 1000) & " Kb", 10, 55, 280, 15, $SS_CENTER)
            ;TrayTip("Downloading", "Downloading Bytes: " & @InetGetBytesRead, 10, 16)
            ;Sleep(250)
            WEnd
                        
            If $Download = @error Or $Download = 0 Then MsgBox(4112, "ERROR!", "An Error has occured with Error #:" & @error)
            ;MsgBox(0,"Filename Location",$filename)
            ;MsgBox(0,"Test Input URL", $URL)
            ;MsgBox(0, "Bytes read", @InetGetBytesRead)
        case $nMsg = $button_close
            Exit
        case $nMsg = $button_abort
            If @InetGetActive Not Then MsgBox(32, "Notice!", "You must have a active download to stop the current download")
            If @InetGetActive Then
                InetGet("abort")
                MsgBox(32, "Notice!", "The download was successfuly aborted")
            EndIf
EndSelect
WEnd
Edited by Sarne
Link to comment
Share on other sites

You need the guigetmsg() in the second loop. Actually, for things like this it may be better to use "on event"

************ NOT TESTED

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.2.10.0
    Author:
    
    Script Function:
    Burn Client ISO
    
#ce ----------------------------------------------------------------------------
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <UpDownConstants.au3>

GUICreate("COMPANY ISO Burner", 250, 300)
;GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

GUICtrlCreateLabel("Please select your client from the list.", 5, 5)
$client = GUICtrlCreateList("", 5, 20, 100, 100)
GUICtrlSetData(-1, "CLIENT1|CLIENT2|CLIENT3|CLIENT4|CLIENT4|CLIENT5", "")

GUICtrlCreateLabel("Please enter your Agent ID", 5, 125)
$AgentID = GUICtrlCreateInput("111301", 5, 140, 70, 20)
GUICtrlCreateUpdown(-1)

$progress = GUICtrlCreateProgress(5, 175, 200, 10)

$button_submit = GUICtrlCreateButton("SUBMIT", 175, 250, 60)
$button_close = GUICtrlCreateButton("CLOSE", 5, 250, 60)
$button_abort = GUICtrlCreateButton("ABORT", 175, 220, 60)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $button_submit
            If GUICtrlRead($client) = "CLIENT1" Then
                $clientDir = "CLIENT1"
                $ClientFile = "Client1"
                $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
                $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"

            ElseIf GUICtrlRead($client) = "CLIENT2" Then
                $clientDir = "CLIENT2"
                $ClientFile = "aiz"
                $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.2.iso"
                $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.2.iso"

            ElseIf GUICtrlRead($client) = "CLIENT3" Then
                $clientDir = "CLIENT3"
                $ClientFile = "Client3"
                $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
                $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"

            ElseIf GUICtrlRead($client) = "CLIENT4" Then
                $clientDir = "CLIENT4"
                $ClientFile = "Client4"
                $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v5.0.4.iso"
                $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v5.0.4.iso"

            ElseIf GUICtrlRead($client) = "CLIENT4" Then
                $clientDir = "CLIENT4"
                $ClientFile = "Client4"
                $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v5.0.4.iso"
                $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v5.0.4.iso"

            ElseIf GUICtrlRead($client) = "CLIENT5" Then
                $clientDir = "CLIENT5"
                $ClientFile = "Client5"
                $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.1.iso"
                $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.1.iso"
            EndIf
            ;MsgBox(0,"Filename Location",$filename)
            ;MsgBox(0,"Test Input URL", $URL)
            $Download = InetGet($URL, $filename, 0, 1)

            $dlsize = InetGetSize($URL)

;~             GUISetState()
            While @InetGetActive
                $nMsg2 = GUIGetMsg()
                If $nMsg2 = $button_abort Then
                    InetGet("abort")
                    MsgBox(0, "Download Aborted", "Your Download has been successfully aborted")
                    ExitLoop
                EndIf
                Sleep(50)
                GUICtrlSetData($progress, Int((@InetGetBytesRead / $dlsize) * 100))
                ;GUICtrlCreateLabel( Int(@InetGetBytesRead / 1000) & " Kb / " & Int($dlsize / 1000) & " Kb", 10, 55, 280, 15, $SS_CENTER)
                ;TrayTip("Downloading", "Downloading Bytes: " & @InetGetBytesRead, 10, 16)
                ;Sleep(250)
            WEnd

            If $Download = @error Or $Download = 0 Then MsgBox(4112, "ERROR!", "An Error has occured with Error #:" & @error)
            ;MsgBox(0,"Filename Location",$filename)
            ;MsgBox(0,"Test Input URL", $URL)
            ;MsgBox(0, "Bytes read", @InetGetBytesRead)
        Case $nMsg = $button_close
            Exit
        Case $nMsg = $button_abort
;~             If @InetGetActive Not Then MsgBox(32, "Notice!", "You must have a active download to stop the current download")
            If @InetGetActive Then
                InetGet("abort")
                MsgBox(32, "Notice!", "The download was successfuly aborted")
            Else
                MsgBox(32, "Notice!", "You must have a active download to stop the current download")
            EndIf
    EndSelect
WEnd

8)

BTW... Not bad for a first post!!! .. and Welcome to the Autoit Forums!!!

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

as well for your

If GUICtrlRead($client) = "CLIENT1" Then
                                $clientDir = "CLIENT1"
                                $ClientFile = "Client1"
                                $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
                                $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
            ElseIf GUICtrlRead($client) = "CLIENT2" Then

You could use Switch, EndSwitch instead.

like:

Switch GUICtrlRead($client)
            Case "CLIENT1"
                        $clientDir = "CLIENT1"
                        $ClientFile = "Client1"
                        $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
                        $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
            Case "CLIENT2"
                        ;... etc.
EndSwitch

:P

Link to comment
Share on other sites

You need the guigetmsg() in the second loop. Actually, for things like this it may be better to use "on event"

************ NOT TESTED

BTW... Not bad for a first post!!! .. and Welcome to the Autoit Forums!!!

That did it!

Thank you!

:P

Link to comment
Share on other sites

as well for your

If GUICtrlRead($client) = "CLIENT1" Then
                                $clientDir = "CLIENT1"
                                $ClientFile = "Client1"
                                $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
                                $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
            ElseIf GUICtrlRead($client) = "CLIENT2" Then

You could use Switch, EndSwitch instead.

like:

Switch GUICtrlRead($client)
            Case "CLIENT1"
                        $clientDir = "CLIENT1"
                        $ClientFile = "Client1"
                        $filename = "c:\COMPANY\" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
                        $URL = "http://example.com/lx_upload/" & $clientDir & "/" & $ClientFile & "_" & GUICtrlRead($AgentID) & "-v1.0.4.iso"
            Case "CLIENT2"
                        ;... etc.
EndSwitch

:P

I "think" :( I see why this is a better option.

Thank you for your advice!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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