Jump to content

Function sequence


Recommended Posts

For $A1 = 8 To $EPRrow1
If $DutyAdd <> "" and $KeyAdd1 <> "" and $DutyDel <> "" and $KeyDel1 <> "" Then
        Send("HB"& ($oExcel.Application.Cells($A1,2).Value) & ($oExcel.Application.Cells($A1,3).Value))
        Sleep(300)
        Send("{ENTER}")
        Sleep(400)
        Send("H/AUTH "& $AUTH1)
        Sleep(300)
        Send("{ENTER}")
        Sleep(300)
        ADDDTY ()
        DELDTY ()
        ADDKEY ()
        DELKEY ()

Hello. I am trying to run functions ADDDTY () , DELDTY () , ADDKEY ()  , DELKEY () one after the other. However, only the 1st Function (ADDDTY) runs and the rest do not. How do I make sure that all 4 functions run    

Link to comment
Share on other sites

Thank you for your response. By themselves, each function works. Even if I rearrange the order, then only the first function works. 

Func ADDDTY ()
    Send("{ESC}")
    Sleep(300)
    Send("H/DTY"& $DutyAdd)
    Sleep(400)
    Send("{ENTER}")
    Sleep(600)
    Send("{ESC}")
    Sleep(100)
EndFunc 
;==========================================================================================================
;===== ** DELETE DUTY CODE ** ========================================================================================
Func DELDTY ()
    Send("{ESC}")
    Sleep(300)
    Send("H/DTYD"& $DutyDel)
    Sleep(400)
    Send("{ENTER}")
    Sleep(600)
    Send("{ESC}")
    Sleep(100)
EndFunc

 

Link to comment
Share on other sites

Add some error checking for example after each function, MsgBox(4096, "Debug", "ADDDTY() Run") etc...  my guess is that it's losing focus of the application and so you aren't seeing any results, I'd recommend using ControlSend as you can then define the application path.

Link to comment
Share on other sites

I think what is happening is that once it leaves the main function and goes to ADDDTY (), it never comes back to execute the next function DELDTY ()

For $A1 = 8 To $EPRrow1
If $DutyAdd <> "" and $KeyAdd1 <> "" and $DutyDel <> "" and $KeyDel1 <> "" Then
        Send("HB"& ($oExcel.Application.Cells($A1,2).Value) & ($oExcel.Application.Cells($A1,3).Value))
        Sleep(300)
        Send("{ENTER}")
        Sleep(400)
        Send("H/AUTH "& $AUTH1)
        Sleep(300)
        Send("{ENTER}")
        Sleep(300)
        ADDDTY ()
        DELDTY ()
        
;===== ** ADD DUTY ** ========================================================================================
Func ADDDTY ()
    Send("{ESC}")
    Sleep(300)
    Send("H/DTY"& $DutyAdd)
    Sleep(400)
    Send("{ENTER}")
    Sleep(600)
    Send("{ESC}")
    Sleep(100)
EndFunc 
;==========================================================================================================
;===== ** DELETE DUTY ** ========================================================================================
Func DELDTY ()
    Send("{ESC}")
    Sleep(300)
    Send("H/DTYD"& $DutyDel)
    Sleep(400)
    Send("{ENTER}")
    Sleep(600)
    Send("{ESC}")
    Sleep(100)
EndFunc 
;=====================================

 

Link to comment
Share on other sites

ADDDTY ()
MsgBox($MB_ICONINFORMATION, "Debug", "ADDDTY has run")
DELDTY ()
MsgBox($MB_ICONINFORMATION, "Debug", "DELDTY has run")

Did that. I dont get the the first message. Which makes me feel that it is not coming back once it goes to ADDDTY ()

Edited by Vikramjeet
Link to comment
Share on other sites

1 hour ago, Vikramjeet said:

I think what is happening is that once it leaves the main function and goes to ADDDTY (), it never comes back to execute the next function DELDTY ()

For $A1 = 8 To $EPRrow1
If $DutyAdd <> "" and $KeyAdd1 <> "" and $DutyDel <> "" and $KeyDel1 <> "" Then
        Send("HB"& ($oExcel.Application.Cells($A1,2).Value) & ($oExcel.Application.Cells($A1,3).Value))
        Sleep(300)
        Send("{ENTER}")
        Sleep(400)
        Send("H/AUTH "& $AUTH1)
        Sleep(300)
        Send("{ENTER}")
        Sleep(300)
        ADDDTY ()
        DELDTY ()
        
;===== ** ADD DUTY ** ========================================================================================
Func ADDDTY ()
    Send("{ESC}")
    Sleep(300)
    Send("H/DTY"& $DutyAdd)
    Sleep(400)
    Send("{ENTER}")
    Sleep(600)
    Send("{ESC}")
    Sleep(100)
EndFunc 
;==========================================================================================================
;===== ** DELETE DUTY ** ========================================================================================
Func DELDTY ()
    Send("{ESC}")
    Sleep(300)
    Send("H/DTYD"& $DutyDel)
    Sleep(400)
    Send("{ENTER}")
    Sleep(600)
    Send("{ESC}")
    Sleep(100)
EndFunc 
;=====================================

 

Where is the NEXT that ends the FOR statement?  Also, where is the EndIf that ends the IF statement?

Edited by TheXman
Link to comment
Share on other sites

;===== ** SELECTION ** ========================================================================================
START ()
FUNC START ()

If $DutyCodeAdd <> "" Then  ;'If' this applies then run ADDDTY() and then move to the next If. However if this 'If' does not apply, then move to next 'If"
    For $A1 = 8 To $EPRrow1
        Send("HB"& ($oExcel.Application.Cells($A1,2).Value) & ($oExcel.Application.Cells($A1,3).Value))
        Sleep(300)
        Send("{ENTER}")
        Sleep(400)
        Send("H/AUTH "& $AUTH1)
        Sleep(300)
        Send("{ENTER}")
        Sleep(300)
        ADDDTY ()
            If $DutyCodeDel <> "" Then ;'If' this applies then run DELDTY() and then move to the next If. However if this 'If' does not apply, then move to                                         ;next 'If'
            DELDTY ()
                If $KeywordsAdd1 <> "" Then  ; 'If' this applies then run ADDKEY() and then move to the next If. However if this 'If' does not apply, then                                                  ;move to next 'If"
                ADDKEY ()
                    If $KeywordsDel1 <> "" Then  ;'If' this applies then run DELKEY(). However if this 'If' does not apply, then do nothing
                    DELKEY ()
                    EndIf
                EndIf
            EndIf
        Send("HE")
        Sleep(300)
        Send("{ENTER}")
        Sleep(300)
        Send("{ESC}")
        Sleep(300)
        Send("I")
        Sleep(300)
        Send("{ENTER}")
        Sleep(300)
        Send("{ESC}")
        Sleep(300)
    Next
EndIf 
            
    $oExcel.Application.Quit
    MsgBox($MB_ICONINFORMATION, "INFORMATION", "Processing Complete")
EndFunc 

;===== ** ADD DUTY CODE ** ========================================================================================
Func ADDDTY ()
    Send("{ESC}")
    Sleep(300)
    Send("H/DTY"& $DutyCodeAdd)
    Sleep(400)
    Send("{ENTER}")
    Sleep(600)
    Send("{ESC}")
    Sleep(100)  
EndFunc 
;==========================================================================================================
;===== ** DELETE DUTY CODE ** ========================================================================================
Func DELDTY ()
    Send("{ESC}")
    Sleep(300)
    Send("H/DTYD"& $DutyCodeDel)
    Sleep(400)
    Send("{ENTER}")
    Sleep(600)
    Send("{ESC}")
    Sleep(100)
EndFunc 
;==========================================================================================================

Here is the code. I am trying to do this
1- If Condition 1 matches ,Then       (If Condition 1 does not match then do nothing and move to step 2)

Do something and move to next If. (Step 2)
2- If Condition 2 matches, Then       (If Condition 2 does not match then do nothing and move to step 3)

Do something and move to next If. (Step 3) 

3- If Condition 3 matches, Then       (If Condition 3 does not match then do nothing and move to step 4)

Do something and move to next If. (Step 4)

4- If Condition 4 matches, Then

Do something and End 

Link to comment
Share on other sites

 

You obviously are not running your code through AU3Check.  Because if you were, you would see the following errors and warnings:

 

>Running AU3Check (3.3.14.5)  params:-w 3 -w 4 -w 6  from:C:\Portable Apps\AutoIt3  input:C:\Projects\Personal\AutoIt\Test\a3_temp.au3
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(5,17) : warning: $DutyCodeAdd: possibly used before declaration.
If $DutyCodeAdd <>
~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(6,28) : warning: $EPRrow1: possibly used before declaration.
    For $A1 = 8 To $EPRrow1
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(7,59) : warning: $oExcel: possibly used before declaration.
        Send("HB"& ($oExcel.Application.Cells($A1,2).Value)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(11,31) : warning: $AUTH1: possibly used before declaration.
        Send("H/AUTH "& $AUTH1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(16,29) : warning: $DutyCodeDel: possibly used before declaration.
            If $DutyCodeDel <>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(18,34) : warning: $KeywordsAdd1: possibly used before declaration.
                If $KeywordsAdd1 <>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(20,38) : warning: $KeywordsDel1: possibly used before declaration.
                    If $KeywordsDel1 <>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(41,31) : warning: $MB_ICONINFORMATION: possibly used before declaration.
    MsgBox($MB_ICONINFORMATION,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(5,17) : error: $DutyCodeAdd: undeclared global variable.
If $DutyCodeAdd <>
~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(6,28) : error: $EPRrow1: undeclared global variable.
    For $A1 = 8 To $EPRrow1
~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(7,59) : error: $oExcel: undeclared global variable.
        Send("HB"& ($oExcel.Application.Cells($A1,2).Value)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(11,31) : error: $AUTH1: undeclared global variable.
        Send("H/AUTH "& $AUTH1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(16,29) : error: $DutyCodeDel: undeclared global variable.
            If $DutyCodeDel <>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(18,34) : error: $KeywordsAdd1: undeclared global variable.
                If $KeywordsAdd1 <>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(20,38) : error: $KeywordsDel1: undeclared global variable.
                    If $KeywordsDel1 <>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(41,31) : error: $MB_ICONINFORMATION: undeclared global variable.
    MsgBox($MB_ICONINFORMATION,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(19,25) : error: ADDKEY(): undefined function.
                ADDKEY ()
~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Projects\Personal\AutoIt\Test\a3_temp.au3"(21,29) : error: DELKEY(): undefined function.
                    DELKEY ()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Projects\Personal\AutoIt\Test\a3_temp.au3 - 10 error(s), 8 warning(s)

 

Link to comment
Share on other sites

23 minutes ago, Vikramjeet said:

Here is the code. I am trying to do this
1- If Condition 1 matches ,Then       (If Condition 1 does not match then do nothing and move to step 2)

Do something and move to next If. (Step 2)
2- If Condition 2 matches, Then       (If Condition 2 does not match then do nothing and move to step 3)

Do something and move to next If. (Step 3) 

3- If Condition 3 matches, Then       (If Condition 3 does not match then do nothing and move to step 4)

Do something and move to next If. (Step 4)

4- If Condition 4 matches, Then

Do something and End 

If <cond1> Then
    ;do something
EndIf

If <cond2> Then
    ;do something
EndIf

If <cond3> Then
    ;do something
EndIf

If <cond4> Then
    ;do something
EndIf

Exit or Return

 

Edited by TheXman
Link to comment
Share on other sites

For $A1 = 8 To $EPRrow1
    Send("HB"& ($oExcel.Application.Cells($A1,2).Value) & ($oExcel.Application.Cells($A1,3).Value))
    Sleep(300)
    Send("{ENTER}")
    Sleep(400)
    Send("H/AUTH "& $AUTH1)
    Sleep(300)
    Send("{ENTER}")
    Sleep(300)
    If $DutyCodeAdd <> "" Then  
        ADDDTY ()
    EndIf   
    If $DutyCodeDel <> "" Then
        DELDTY ()
    EndIf
    If $KeywordsAdd1 <> "" Then
        ADDKEY ()
    EndIf
    If $KeywordsDel1 <> "" Then
        DELKEY ()
    EndIf
                
    Send("HE")
    Sleep(300)
    Send("{ENTER}")
    Sleep(300)
    Send("{ESC}")
    Sleep(300)
    Send("I")
    Sleep(300)
    Send("{ENTER}")
    Sleep(300)
    Send("{ESC}")
    Sleep(300)
Next

Lean and clean 😉

Link to comment
Share on other sites

If you are just executing a single statement, then you can make it even leaner & cleaner:

If $DutyCodeAdd  <> "" Then ADDDTY()
If $DutyCodeDel  <> "" Then DELDTY()
If $KeywordsAdd1 <> "" Then ADDKEY()
If $KeywordsDel1 <> "" Then DELKEY()

😀

Edited by TheXman
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...