Sign in to follow this  
Followers 0
monte

error catching

10 posts in this topic

hello, I want to test for an error and continue loop if occurs instead of crashing my script. Specifically, my data is copied from the clipbaord and then used in my function. If however, the correct data isn't in the clipboard, the script fails, see $vServer=$vServerString[22] below. Instead of crashing, I want to be able to continue loop. Thanks for any help you may be able to provide. here's my code:

#include <GUIConstants.au3>
#include <array.au3>
#notrayicon
$checkRun = "Emc Script"
If WinExists($checkRun) Then Exit

GUICreate("Emc Script", 350, 210)
GUISetBkColor (0xA9A9A9)

$button1 = GUICtrlCreateIcon ("C:\progra~1\pa.bmp",-1,10,10) ; pa
GUISetState ()

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
   Select
      Case $msg = $button1
         pa()
         if @error then continueloop
   EndSelect
WEnd

func pa()
 seterror(1)
 If WinExists("pa") Then
  $vServerClip=clipget()
  $vServerString=stringsplit($vServerClip,@TAB)
  $vServer=$vServerString[22]
  WinActivate("pa")
  sleep(1000)
  Send("{F10}tf")
  Send($vServer)
  send("{TAB}a")
  Send("{ENTER}")
  sleep(1000)
  send("{ENTER}")
 else
  global $mycmd="C:\progra~1\citrix\icacli~1\pn.exe /pn:" & '"farm"' & ' /app:"pa Client"'
  Dim $primary
  Dim $secondary
  $k = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")
  If $k = 1 Then
   $primary = "right"
   $secondary = "left"
  else 
   $primary = "left"
   $secondary = "right"
  endIf
  msgbox(1,"","Opening pa, please have your rsa token ready.  If the server search does not commence upon entering, please reclick the pa icon.", 20)
  run($mycmd)
  WinWaitActive("pa")
  winactivate("pa")
  MouseClick($Primary, 160,140, 2, 0)
  sleep(20000)
  winactivate("pa")
  $vServerClip=clipget()
  $vServerString=stringsplit($vServerClip,@TAB)
  $vServer=$vServerString[22]
  Send("{F10}tf")
  Send($vServer)
  send("{TAB}a")
  Send("{ENTER}")
  sleep(1000)
  send("{ENTER}")
  sleep(300)
 endif
endfunc
[\code]


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                        





(adsbygoogle = window.adsbygoogle || []).push({});




                    
                
                    
                    
                    






    
    
        
Valuater   

    
        
    
             84
    
        
    

        
            
                Universalist
            
            

            
                

    
        
    

            
            MVPs
            
                
            
            
                

    
        
    
             84
    
        
    

                11,084 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #2 · 
            Posted 
            
            
            
        
    

    


            
        
            
8)


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
            




  
  
    


  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
cdkid   

    
        
    
             1
    
        
    

        
            
                El Spamino
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             1
    
        
    

                715 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #3 · 
            Posted 
            
            
            
        
    

    


            
        
            /me is probably way off-base but
in ur loop try
if @error <> 0 then continueloop

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

/me is probably way off-base but

in ur loop try

if @error <> 0 then continueloop
Yep, probably he/she needs check if StringSplit() returns any array. :o

Share this post


Link to post
Share on other sites

sorry about the code:

#include <GUIConstants.au3>
#include <array.au3>
#notrayicon
$checkRun = "Emc Script"
If WinExists($checkRun) Then Exit

GUICreate("Emc Script", 350, 210)
GUISetBkColor (0xA9A9A9)

$button1 = GUICtrlCreateIcon ("C:\progra~1\pa.bmp",-1,10,10); pa
GUISetState ()

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Select
Case $msg = $button1
pa()
if @error then continueloop
EndSelect
WEnd

func pa()
seterror(1)
If WinExists("pa") Then
$vServerClip=clipget()
$vServerString=stringsplit($vServerClip,@TAB)
$vServer=$vServerString[22]
WinActivate("pa")
sleep(1000)
Send("{F10}tf")
Send($vServer)
send("{TAB}a")
Send("{ENTER}")
sleep(1000)
send("{ENTER}")
else
global $mycmd="C:\progra~1\citrix\icacli~1\pn.exe /pn:" & '"farm"' & ' /app:"pa Client"'
Dim $primary
Dim $secondary
$k = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")
If $k = 1 Then
$primary = "right"
$secondary = "left"
else 
$primary = "left"
$secondary = "right"
endIf
msgbox(1,"","Opening pa, please have your rsa token ready. If the server search does not commence upon entering, please reclick the pa icon.", 20)
run($mycmd)
WinWaitActive("pa")
winactivate("pa")
MouseClick($Primary, 160,140, 2, 0)
sleep(20000)
winactivate("pa")
$vServerClip=clipget()
$vServerString=stringsplit($vServerClip,@TAB)
$vServer=$vServerString[22]
Send("{F10}tf")
Send($vServer)
send("{TAB}a")
Send("{ENTER}")
sleep(1000)
send("{ENTER}")
sleep(300)
endif
endfunc

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

you are trying to make a button with an icon... thats ok.. but

$button1 = GUICtrlCreateIcon ("C:\progra~1\pa.bmp",-1,10,10); pa

you are using a .bmp.... and i dont think that will work

remove SetError(1)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

try

Edit: put another check on the array

#include <GUIConstants.au3>
#include <array.au3>
#notrayicon
$checkRun = "Emc Script"
If WinExists($checkRun) Then Exit

GUICreate("Emc Script", 350, 210)
GUISetBkColor(0xA9A9A9)

$button1 = GUICtrlCreatePic("C:\progra~1\pa.bmp", 10, 10); pa
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Select
        Case $msg = $button1
            pa()
    EndSelect
WEnd

Func pa()
    If WinExists("pa") Then
        $vServerClip = ClipGet()
        $vServerString = StringSplit($vServerClip, @TAB)
        If IsArray($vServerString) Then
            If $vServerString[0] >= 22 Then $vServer = $vServerString[22]
        EndIf
        WinActivate("pa")
        Sleep(1000)
        Send("{F10}tf")
        Send($vServer)
        Send("{TAB}a")
        Send("{ENTER}")
        Sleep(1000)
        Send("{ENTER}")
    Else
        Global $mycmd = "C:\progra~1\citrix\icacli~1\pn.exe /pn:" & '"farm"' & ' /app:"pa Client"'
        Local $primary
        Local $secondary
        $k = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")
        If $k = 1 Then
            $primary = "right"
            $secondary = "left"
        Else
            $primary = "left"
            $secondary = "right"
        EndIf
        MsgBox(1, "", "Opening pa, please have your rsa token ready. If the server search does not commence upon entering, please reclick the pa icon.", 20)
        Run($mycmd)
        WinWaitActive("pa")
        WinActivate("pa")
        MouseClick($primary, 160, 140, 2, 0)
        Sleep(20000)
        WinActivate("pa")
        $vServerClip = ClipGet()
        $vServerString = StringSplit($vServerClip, @TAB)
        If IsArray($vServerString) Then
            If $vServerString[0] >= 22 Then $vServer = $vServerString[22]
        EndIf
        Send("{F10}tf")
        Send($vServer)
        Send("{TAB}a")
        Send("{ENTER}")
        Sleep(1000)
        Send("{ENTER}")
        Sleep(300)
    EndIf
EndFunc  ;==>pa
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I've tried the following and my script failed when I didn't have the correct data in the clipboard. and stringsplit returns an array.

Case $msg = $button1

privateArk()

if @error <> 0 then continueloop

I also tried removing seterror(1) and keeping both:

if @error <> 0 then continueloop

and

if @error then continueloop

both still crash script. Thanks for your help

Share this post


Link to post
Share on other sites

I've tried the following and my script failed when I didn't have the correct data in the clipboard. and stringsplit returns an array.

Case $msg = $button1

privateArk()

if @error <> 0 then continueloop

I also tried removing seterror(1) and keeping both:

if @error <> 0 then continueloop

and

if @error then continueloop

both still crash script. Thanks for your help

Check the gafrost's suggestion. Maybe your problem is with StringSplit() output.

Share this post


Link to post
Share on other sites

Thank you guys for all your help (including girls if there were any). I created an if else ( If $vServerString[0] >= 22 Then ) within my original if else and removed my seterror and if @error. This works....I I don't know why I didn't think of it earlier. *duh* Thank you guys so much! You were a real help!

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