Jump to content

Loop if, else, then


Recommended Posts

But you have to work with all $variable exactly same way as $File $Variable. Or some data wont be accessible. Or not declared before being used. this is why sometime you see that at the beginning of the script:

 

Global $cIPADD
Global $cIPADD2
Global $cIPADD3
Global $cIPADD4
   ;Info printers
   Global $cIMPIP = ""
   Global $cIMPName
   Global $cIMPDrivers = @ScriptDir&"\Drivers\UFRII_Driver_V3015_32_64_FR_02\x64\Driver"
   ;Noms imprimantes
   Global $cIMPRdC1 = ""
   Global $cIMPIPRdC1 = "10.81.99.6"
   Global $cIMP1er1 = ""
   Global $cIMPIP1er1 = "10.81.99.2"
   Global $cIMP2e1 = ""
   Global $cIMPIP2e1 = "10.81.99.17"
   Global $cIMP2e2 = ""
   Global $cIMPIP2e2 = "10.81.99.3"
   Global $cIMP2e3 = ""
   Global $cIMPIP2e3 = ""
      ;Presence ou absence suite scan log
      Global $cPresenceUAC
      Global $cPresenceMirrorOP
      Global $cPresenceAdobe

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible =  0
#include <MsgBoxConstants.au3>
#Include <File.au3>
Global $arlines

WinActivate("MyApplication")
Local $hWnd = WinWaitActive("MyApplication", "", 5)

$oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\List.xlsx")
local $iCell = $oExcel.Application.Cells(31,1).Value

$file = @ScriptDir & "\DATA.log"

Start ()
Func Start ()
If $hWnd Then
;--------------------------------------------------------------------------------------------
    For $a = 1 to $iCell    ;Master Loop-Loop 1. Value of loop counter comes from an excel file
    Send("G*L")
    Send($oExcel.Application.Cells($a,1).Value)
    Send("/XTIM")
    Sleep(1000)
    Send("{ENTER}")
    Sleep(2000)
   Local $file = "DATA.log", $data = ""
        $lines = _FileCountLines($file)
;-------------------------------------------------------------------------------------------        
            MsgBox(0,"",$lines)
            For $i = $lines-4 To $lines ; Sub Loop- Loop 1A. Value comes from total lines in log file 
            $data = FileReadLine($file, $i) ;Total lines in log file
            MsgBox(0,"", $data)     ;Message with total lines in file is displayed. This is just to check the script
            If $data = "‡NONE LISTED" Then    ;As script is reading the last 5 lines of the log file in a loop,if text 'NONE LISTED' is found then exit loop
            MsgBox (0,"", "Awesome") ; This is just to check the script
            ExitLoop    ;Exit loop 1A and go to Loop 1 to start next sequence
            Else        ;Else if text 'NONE LISTED' is not found then read the last occurance of 1-3 numbers in the log file and perform loop 1B
;------------------------------------------------------------------------------------------------
                $file = @ScriptDir & "\DATA.log"
                $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0]
                ConsoleWrite($iNum & @CRLF)
                For $i = 1 To $iNum ; Loop 1B
                Send("GTIM"& $i &"/OVR")
                Sleep(500)
                Send("{ENTER}")
                Sleep(1000)
                Next
                EndIf
            Endif
        Next            ; Go to next sequence of Loop 1
    Next
Endif
$oExcel.Application.Quit

I definitely need help with the sequence of loops. I need to run 3 loops. Loop 1 is the Master loop. Loop 1A and Loop 1B are within Master Loop 1
1- Start Master Loop 1
2- Within Loop 1, start Loop 1A
3- If specific text is found during Loop 1A, then exit Loop 1A and go to next sequence of Master Loop 1
4- Else start Loop 1B
5- Once Loop 1B is complete, then go to next sequence of Master Loop 1

In my previous posts, I have been able to successfully run Loop 1 and 1A the way I want. Please help with adding loop 1B in the above script

Edited by Vikramjeet
Link to comment
Share on other sites

1- Start Master Loop 1
2- Within Loop 1, start Loop 1A
3- If specific text is found during Loop 1A, then exit Loop 1A and go to next sequence of Master Loop 1
4- Else start Loop 1B
5- Once Loop 1B is complete, then go to next sequence of Master Loop 1

 

 

 

While (1) ;Master loop

    While (1) ; Loop 1A
        ; You said you want ExitLoop 1A if you find a specific text so Exit after you found your text
        If $specificText Then 
            ExitLoop ; => WEnd of Loop 1A
        Else
            While (1) ; Loop 1B
                ; You do loop 1B in Else condition
                If $specificText Then
                ... ; My stuff
                ExitLoop ; Then =>WEnd of loop 1B
                Else            
                ExitLoop ; Then =>WEnd of loop 1B
                EndIf
            WEnd ; => End of loop 1B
            ExitLoop ; If you Exit loop 1B you are still in loop 1A so you have to leave it too, ( if you want 
        EndIf
    WEnd ; => End of loop 1A => Next sequance
    
;>Next sequence ================
    ;My next sequence 
    ...
    ...
    ...
    While (1); Additional Loop
        If ... Then 
            ExitLoop            
        EndIf
    WEnd
    ...
    ...
    ...
;>Next sequence /===============

WEnd ; => Master Loop
If ... Then 
    NextSeq () 
EndIF   
 

Func NextSeq ()
;>Next sequence ================
    ;My next sequence 
    ...
    ...
    ...
    While (1); Additional Loop
        If ... Then 
            ExitLoop            
        EndIf
    WEnd
    ...
    ...
    ...
;>Next sequence /===============
EndFunc

Mix of both above exemple : 

 

While (1) ;Master loop

    While (1) ; Loop 1A
        If $specificText Then 
            ExitLoop 
        Else
            While (1) 
                If $specificText Then
                ... 
                ExitLoop 
                Else            
                ExitLoop 
                EndIf
            WEnd
            Nextseq () ; Now all you requirement are meet. You got the next seq after loop B only. with simple line since you got everything inside a function.
            ExitLoop ; Dont forget to leave :) 1A
        EndIf
    WEnd 
    


WEnd 

 

Func NextSeq ()
;>Next sequence ================
    ...
    ...
    ...
    While (1); Additional Loop
        If ... Then 
            ExitLoop            
        EndIf
    WEnd
    ...
    ...
    ...
;>Next sequence /===============
EndFunc

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

1 hour ago, Vikramjeet said:

Once Loop 1B is complete, then go to next sequence of Master Loop 1

 

1 hour ago, Vikramjeet said:

; Go to next sequence of Loop 1

When you think about how to parse everything in your mind you have to replace the word GO by DO

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

I want to 
1- Start Loop 1
2- Start Loop 1A. If text found then Go to next sequence of Loop 1
3- If during Loop 1A, text is Not found then go to loop 1B. There will be no condition is Loop 1B so we let it run and complete
4-Once Loop 1B is complete then go to next sequence of Loop 1

 

 

Link to comment
Share on other sites

Just now, Vikramjeet said:

I want to 
1- Start Loop 1
2- Start Loop 1A. If text found then Go to next sequence of Loop 1
3- If during Loop 1A, text is Not found then go to loop 1B. There will be no condition is Loop 1B so we let it run and complete
4-Once Loop 1B is complete then go to next sequence of Loop 1

 

 

You can do what ever you want :) Try and show us. 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

It is easyer to add code on this code than in your :

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

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <MsgBoxConstants.au3>
#Include <File.au3>

Local $oExcel = ObjCreate("Excel.Application")
Local $oExcel.Visible =  0
Global $file = @ScriptDir & "\DATA.log"
Global $arlines
Global $data
Global $lines
Global $iNum

WinActivate("MyApplication")
Local $hWnd = WinWaitActive("MyApplication", "", 5)

$oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\List.xlsx")
Global $iCell = $oExcel.Application.Cells(31,1).Value

Start ()

Func Start ()
   If $hWnd Then
      For $a = 1 to $iCell    ;Loop 1
      Send("G*L")
      Send($oExcel.Application.Cells($a,1).Value)
      Send("/XTIM")
      Sleep(1000)
      Send("{ENTER}")
      Sleep(2000)
      Local $file = "DATA.log", $data = ""
      $lines = _FileCountLines($file)
      MsgBox(0,"",$lines)
      Loop1A ()
      Next
   Endif
$oExcel.Application.Quit
EndFunc

Func Loop1A ()
   For $i = $lines-4 To $lines ;Loop 1A
   $data = FileReadLine($file, $i)
   MsgBox(0,"", $data)
      If $data = "‡NONE LISTED" Then
      MsgBox (0,"", "Awesome")
      ExitLoop
      Else
      $file = @ScriptDir & "\DATA.log"
      $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0]
      ConsoleWrite($iNum & @CRLF)
      Loop1B ()
      EndIf
   Next
EndFunc

Func Loop1B ()
   For $i = 1 To $iNum ; Loop 1B
   Send("GTIM"& $i &"/OVR")
   Sleep(500)
   Send("{ENTER}")
   Sleep(1000)
   Next
EndFunc

Check if all declaration are correct. And now say me in that what would you like to add ?

 

But still there is some error that you have to correct.

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

58 minutes ago, caramen said:

It is easyer to add code on this code than in your :

#include <MsgBoxConstants.au3>
#Include <File.au3>

Global $oExcel = ObjCreate("Excel.Application")
Global $oExcel.Visible =  0
Global $file = @ScriptDir & "\DATA.log"
Global $arlines
Global $data
Global $lines

WinActivate("MyApplication")
Global $hWnd = WinWaitActive("MyApplication", "", 5)

Global $oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\List.xlsx")
Global $iCell = $oExcel.Application.Cells(31,1).Value

Start ()

Func Start ()
   If $hWnd Then
      For $a = 1 to $iCell    ;Loop 1
      Send("G*L")
      Send($oExcel.Application.Cells($a,1).Value)
      Send("/XTIM")
      Sleep(1000)
      Send("{ENTER}")
      Sleep(2000)
      Local $file = "DATA.log", $data = ""
      $lines = _FileCountLines($file)        
      MsgBox(0,"",$lines)
      Loop1A ()
      Next
   Endif
$oExcel.Application.Quit
EndFunc

Func Loop1A ()
   For $i = $lines-4 To $lines ;Loop 1A
   $data = FileReadLine($file, $i) 
   MsgBox(0,"", $data)     
      If $data = "‡NONE LISTED" Then    
      MsgBox (0,"", "Awesome") 
      ExitLoop    
      Else        
      $file = @ScriptDir & "\DATA.log"
      $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0]
      ConsoleWrite($iNum & @CRLF)
      Loop1B ()
      EndIf
      Endif
      Next
EndFunc
         
Func Loop1B ()
   For $i = 1 To $iNum ; Loop 1B
   Send("GTIM"& $i &"/OVR")
   Sleep(500)
   Send("{ENTER}")
   Sleep(1000)
   Next
EndFunc

Check if all declaration are correct. And now say me in that what would you like to add ?

 

But still there is some error that you have to correct.

This is days ahead of where I was. You are an Expert. It is working 'better'. Loop 3 counter is off. I am playing to fix it. Thank you so much 'Master'

Link to comment
Share on other sites

1 hour ago, Vikramjeet said:

This is turning out to be extremely difficult.

This is because everyone here is "giving you fishes instead of teaching you how to fish".

Try yourself what you are trying to do, and write here only if you are not able to do that.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

9 minutes ago, FrancescoDiMuro said:

This is because everyone here is "giving you fishes instead of teaching you how to fish".

Try yourself what you are trying to do, and write here only if you are not able to do that.

I respectfully disagree. I have been doing a lot of research to write the script. Others have been nice to point me to to the right direction and I have learnt. I wrote the script you see here. Thank you

Link to comment
Share on other sites

Dont worry @FrancescoDiMuro is also pointing you to the right direction when he is saying this. It will take you much mooooore time to understand something hard but it is so much better for the feeling :)

 

This is why i am trying to help in the abstract way first...

 

@Vikramjeet Where is loop 3 ? keep it simple, loop 3 is 1B ?

Debug the next code next time and come with the return of your SciTe console :)

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

It s like you did not asked or i would not post that.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

4 minutes ago, caramen said:

Dont worry @FrancescoDiMuro is also pointing you to the right direction when he is saying this. It will take you much mooooore time to understand something hard but it is so much better for the feeling :)

 

This is why i am trying to help in the abstract way first...

 

@Vikramjeet Where is loop 3 ? keep it simple, loop 3 is 1B ?

Debug the next code next time and come with the return of your SciTe console :)

Yes, sorry its loop 1B

Link to comment
Share on other sites

Give it a try.

Come with a non working exemble.

Becose of commands/function not becose of structure. :P

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

#include <MsgBoxConstants.au3>
#Include <File.au3>

$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible =  0
Global $file = @ScriptDir & "\DATA.log"
Global $data
Global $lines
Global $iNum
Global $iCatch

WinActivate("MyApplication")
Global $hWnd = WinWaitActive("MyApplication", "", 5)

$oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\List.xlsx")
Global $iCell = $oExcel.Application.Cells(31,1).Value

Start ()
Func Start ()
    If $hWnd Then
        For $a = 1 to $iCell    ;Loop 1
        Send("G*L")
        Send($oExcel.Application.Cells($a,1).Value)
        Send("/XTIM")
        Sleep(1000)
        Send("{ENTER}")
        Sleep(2000)
        Send("MB")
        Send("{ENTER}")
        Sleep(2000)
        Local $file = "DATA.log", $data = ""
        $lines = _FileCountLines($file)        
        ;MsgBox(0,"",$lines)
        $iCatch = (FileReadLine($file, $lines) & FileReadLine($file, $lines-1) & FileReadLine($file, $lines-2) & FileReadLine($file, $lines-3) & FileReadLine($file, $lines-4) & FileReadLine($file, $lines-5))
        ;MsgBox(0,"", $iCatch) ======> Just for me to see the script read the lines
            If StringRegExp($iCatch, "‡NONE LISTED") Then
                ;MsgBox(0,"", "CAUGHT") =============> Only used to test
                ContinueLoop
            Else
                $file = @ScriptDir & "\DATA.log"
                $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0]
                ConsoleWrite($iNum & @CRLF)
                Loop2 ()
            EndIf
        Next
    EndIf
$oExcel.Application.Quit
EndFunc
         
Func Loop2 ()
    For $i = 1 To $iNum
    Send("G"& $i &"/TKT")
    Sleep(500)
    Send("{ENTER}")
    Sleep(1000)
    Next
EndFunc

Finally after almost a week.....Its working!!!! The script is performing the tasks exactly as I wanted
I could still not figure out how to handle multiple loops. So I changed the script to avoid one loop and still get what I want. Now I have 2 loops which was easier for me to handle
Special Thanks to Caramen. Your suggestions, samples and ideas were extremely useful for me to learn, understand and finally come up with a working script. Everyone learns differently, and for me I learn much faster when I see a script and analyze it. THANK YOU !!! :cheer:

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

×
×
  • Create New...