Jump to content

Crashing when windows not exists


zvvyt
 Share

Recommended Posts

#NoTrayIcon
#include <misc.au3>
#include <guiconstants.au3>
#include <Constants.au3>
#include <IE.au3>
FileInstall("intro.jpg","")
FileInstall("silkroad.jpg","")


;SplashImageOn("Thx for using this!","intro.jpg")
;sleep(2500)
;SplashOff()

Opt("GUIEventOptions",1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)  

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")


$main = GUICreate("Hide Me",160,150)
GUISetIcon("silkroad.jpg")
GUICtrlCreateTab(0,129)
GUICtrlCreateTabitem("Main");Main
$1st = GUICtrlCreateButton("Hide",30,0)
GUICtrlCreateLabel("1st",5,5)
guictrlsetcolor(-1,0xCC0000)
$1stshow = GUICtrlCreateButton("Show",90,0)
$2ndshow = GUICtrlCreateButton("Show",90,25)
$2nd = GUICtrlCreateButton("Hide",30,25)
GUICtrlCreateLabel("2nd",5,30)
guictrlsetcolor(-1,0xCC0000)
$3rdshow = GUICtrlCreateButton("Show",90,50)
$3rd = GUICtrlCreateButton("Hide",30,50)
GUICtrlCreateLabel("3rd",5,55)
guictrlsetcolor(-1,0xCC0000)
$refresh = GUICtrlCreateButton("Refresh client info",30,90)
GUICtrlCreateTabItem("Timer");Timer 
guictrlcreatelabel("Hours",10,5)
$hour = GUICtrlCreateInput("0",10,20,40)
$hupdown = GUICtrlCreateUpdown($hour)
GUICtrlSetLimit($hupdown,23,0)
guictrlcreatelabel("Minutes",60,5)
$minute = guictrlcreateinput("0",60,20,40)
$mupdown = GUICtrlCreateUpdown($minute)
GUICtrlSetLimit($mupdown,59,0)
guictrlcreatelabel("Seconds",110,5)
$second = guictrlcreateinput("0",110,20,40)
$supdown = guictrlcreateupdown($second)
GUICtrlSetLimit($supdown,59,0)
$start = GUICtrlCreateButton("Start",40,50)
$stop = guictrlcreatebutton("Stop",90,50)
GUICtrlSetState($stop,$GUI_DISABLE)
$sSRO = GUICtrlCreateCheckbox("Shutdown SRO",10,75)
$sCOM = GUICtrlCreateCheckbox("Shutdown COM",10,100)
GUICtrlCreateTabItem("Settings");Settings
$GW = GUICtrlCreateInput("SRO_Client",10,10)
GUISetState (@SW_SHOW)
$WN = GUICtrlRead($GW)
$array = WinList($WN)
while 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then Exit
    select 
    Case $msg = $GUI_EVENT_MINIMIZE
        GuiSetState(@SW_MINIMIZE)
        GuiSetState(@SW_HIDE)
        TraySetState(1); show
        TraySetIcon("C:\Program Files\Silkroad\silkroad.ico")
    case $msg = $refresh
            $WN = GUICtrlRead($GW)
            if WinExists($WN) then 
            $array = WinList($WN)
            MsgBox(0,"Running copies",$array[0][0])
        else 
            MsgBox(0,"ErrOr","No window with that name")
        EndIf
    case $msg = $1st
        $WN = GUICtrlRead($GW)
        if not WinExists($WN) then MsgBox(0,"STOP IT!","No copy executed" & @CRLF & "Try execute one")
        if WinExists($WN) then 
        $array = WinList($WN)
        WinSetState($array[1][1],"",@sw_hide)
    endif
    case $msg = $1stshow
        WinSetState($array[1][1],"",@SW_SHOW)
    case $msg = $2nd
        $WN = GUICtrlRead($GW)
        $array1 = WinList($WN)
        if not WinExists($array1[2][1]) then MsgBox(0,"STOP IT!","No copy executed" & @CRLF & "Try execute another one")
        if WinExists($array1[2][1]) then 
        WinSetState($array1[2][1],"",@sw_hide)
    EndIf
    case $msg = $2ndshow
        WinSetState($array[2][1],"",@SW_SHOW)
    case $msg = $3rd
        if WinExists($array[3][1]) Then
        WinSetState($array[3][1],"",@sw_hide)
    else 
        MsgBox(0,"STOP IT!","No 3rd copy executed, try execute it")
    EndIf
    case $msg = $3rdshow
        WinSetState($array[3][1],"",@SW_SHOW)
    case $msg = $start
        $checkhour = GUICtrlRead($hour)
        $checkminute = GUICtrlRead($minute)
        $checksecond = GUICtrlRead($second)
        $tid = $checkhour*3600+$checkminute*60+$checksecond
        For $i = $tid to 0 Step -1
        GUICtrlCreateLabel($i,110,100 )
        sleep(1000)
        Next
        $wSRO = GUICtrlRead($sSRO)
        $wCOM = guictrlread($sCOM)
        if $wSRO = 1 then ProcessClose("sro_client.exe")
        if $wCOM = 1 then Shutdown(1+4)
        if $wSRO = 4 and $wCOM = 4 then MsgBox(0,"Silly","No option chosen, time wasted...")
    EndSelect
WEnd

Func SpecialEvent()
    GuiSetState(@SW_RESTORE)
    GuiSetState(@SW_Show)
    TraySetState(2); hide
EndFunc

i want the commands at line 87 and 96 to give out that msgbox instead of crashing the script/program

want it to have the same purpose as the one at line 78

any solution?

thx in advance

Edited by zvvyt
Link to comment
Share on other sites

#NoTrayIcon
#include <misc.au3>
#include <guiconstants.au3>
#include <Constants.au3>
#include <IE.au3>
FileInstall("intro.jpg","")
FileInstall("silkroad.jpg","")


;SplashImageOn("Thx for using this!","intro.jpg")
;sleep(2500)
;SplashOff()

Opt("GUIEventOptions",1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)  

TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent")


$main = GUICreate("Hide Me",160,150)
GUISetIcon("silkroad.jpg")
GUICtrlCreateTab(0,129)
GUICtrlCreateTabitem("Main");Main
$1st = GUICtrlCreateButton("Hide",30,0)
GUICtrlCreateLabel("1st",5,5)
guictrlsetcolor(-1,0xCC0000)
$1stshow = GUICtrlCreateButton("Show",90,0)
$2ndshow = GUICtrlCreateButton("Show",90,25)
$2nd = GUICtrlCreateButton("Hide",30,25)
GUICtrlCreateLabel("2nd",5,30)
guictrlsetcolor(-1,0xCC0000)
$3rdshow = GUICtrlCreateButton("Show",90,50)
$3rd = GUICtrlCreateButton("Hide",30,50)
GUICtrlCreateLabel("3rd",5,55)
guictrlsetcolor(-1,0xCC0000)
$refresh = GUICtrlCreateButton("Refresh client info",30,90)
GUICtrlCreateTabItem("Timer");Timer 
guictrlcreatelabel("Hours",10,5)
$hour = GUICtrlCreateInput("0",10,20,40)
$hupdown = GUICtrlCreateUpdown($hour)
GUICtrlSetLimit($hupdown,23,0)
guictrlcreatelabel("Minutes",60,5)
$minute = guictrlcreateinput("0",60,20,40)
$mupdown = GUICtrlCreateUpdown($minute)
GUICtrlSetLimit($mupdown,59,0)
guictrlcreatelabel("Seconds",110,5)
$second = guictrlcreateinput("0",110,20,40)
$supdown = guictrlcreateupdown($second)
GUICtrlSetLimit($supdown,59,0)
$start = GUICtrlCreateButton("Start",40,50)
$stop = guictrlcreatebutton("Stop",90,50)
GUICtrlSetState($stop,$GUI_DISABLE)
$sSRO = GUICtrlCreateCheckbox("Shutdown SRO",10,75)
$sCOM = GUICtrlCreateCheckbox("Shutdown COM",10,100)
GUICtrlCreateTabItem("Settings");Settings
$GW = GUICtrlCreateInput("SRO_Client",10,10)
GUISetState (@SW_SHOW)
$WN = GUICtrlRead($GW)
$array = WinList($WN)
while 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then Exit
    select 
    Case $msg = $GUI_EVENT_MINIMIZE
        GuiSetState(@SW_MINIMIZE)
        GuiSetState(@SW_HIDE)
        TraySetState(1); show
        TraySetIcon("C:\Program Files\Silkroad\silkroad.ico")
    case $msg = $refresh
            $WN = GUICtrlRead($GW)
            if WinExists($WN) then 
            $array = WinList($WN)
            MsgBox(0,"Running copies",$array[0][0])
        else 
            MsgBox(0,"ErrOr","No window with that name")
        EndIf
    case $msg = $1st
        $WN = GUICtrlRead($GW)
        if not WinExists($WN) then MsgBox(0,"STOP IT!","No copy executed" & @CRLF & "Try execute one")
        if WinExists($WN) then 
        $array = WinList($WN)
        WinSetState($array[1][1],"",@sw_hide)
    endif
    case $msg = $1stshow
        WinSetState($array[1][1],"",@SW_SHOW)
    case $msg = $2nd
        $WN = GUICtrlRead($GW)
        $array1 = WinList($WN)
        if not WinExists($array1[2][1]) then MsgBox(0,"STOP IT!","No copy executed" & @CRLF & "Try execute another one")
        if WinExists($array1[2][1]) then 
        WinSetState($array1[2][1],"",@sw_hide)
    EndIf
    case $msg = $2ndshow
        WinSetState($array[2][1],"",@SW_SHOW)
    case $msg = $3rd
        if WinExists($array[3][1]) Then
        WinSetState($array[3][1],"",@sw_hide)
    else 
        MsgBox(0,"STOP IT!","No 3rd copy executed, try execute it")
    EndIf
    case $msg = $3rdshow
        WinSetState($array[3][1],"",@SW_SHOW)
    case $msg = $start
        $checkhour = GUICtrlRead($hour)
        $checkminute = GUICtrlRead($minute)
        $checksecond = GUICtrlRead($second)
        $tid = $checkhour*3600+$checkminute*60+$checksecond
        For $i = $tid to 0 Step -1
        GUICtrlCreateLabel($i,110,100 )
        sleep(1000)
        Next
        $wSRO = GUICtrlRead($sSRO)
        $wCOM = guictrlread($sCOM)
        if $wSRO = 1 then ProcessClose("sro_client.exe")
        if $wCOM = 1 then Shutdown(1+4)
        if $wSRO = 4 and $wCOM = 4 then MsgBox(0,"Silly","No option chosen, time wasted...")
    EndSelect
WEnd

Func SpecialEvent()
    GuiSetState(@SW_RESTORE)
    GuiSetState(@SW_Show)
    TraySetState(2); hide
EndFunc

i want the commands at line 87 and 96 to give out that msgbox instead of crashing the script/program

want it to have the same purpose as the one at line 78

any solution?

thx in advance

You need to check if WinList actually returned an array and if it did does the element you are trying to check exist. If you try to use an array element that does not exist the AutoIt will end with this error.

"Array variable has incorrect number of subscripts or subscript dimension range exceeded.:"

Try somthing like this

$array1 = WinList($WN)
If IsArray($array1) Then 
    If $array1[0][0] > 2 Then
        If WinExists($array1[2][1]) Then
            WinSetState($array1[2][1], "", @SW_HIDE)
        EndIf
    Else
        MsgBox(0, "STOP IT!", "No copy executed" & @CRLF & "Try execute another one")
    EndIf
Else
    MsgBox(0, "STOP IT!", "No copy executed" & @CRLF & "Try execute another one")
EndIf

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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...