Jump to content

Loop if, else, then


Recommended Posts

Man.

 

You caanot travel in you script .

Look :

#include <Constants.au3>


Func A ()
   Sleep(10)
EndFunc
   Sleep(50)
   
   If ... Then
         A ()
         Sleep(500)
   EndIf
         B ()
   Sleep(50)


Func B ()
   Sleep(10)
EndFunc

After the If ... Then

If i play my function A it will sleep 510 ms sleep. Not only 10. You cannot travel to a function and leave what the script was gonna do.

If this is your problem you dont got an other solution than rework your script.

 

BUT IN THIS CASE:

#include <Constants.au3>


Func A ()
   Sleep(10)
EndFunc
   Sleep(50)
   
   If ... Then
         A ()
         ExitLoop
         Sleep(500)
   EndIf
         B ()
   Sleep(50)


Func B ()
   Sleep(10)
EndFunc

Yu will sleep only 10 after the line If ... Then

If condition is meet ofc. Then you will sleep (50) after the loop

 

#include <Constants.au3>


Func A ()
   B ()
EndFunc

Func B ()
   C ()
EndFunc

Func C ()
   Sleep (50)
EndFunc

Sleep (50)
Sleep (50)
A ()
Sleep (50)
Sleep (50)

   While (1)
      C ()
   WEnd

In this case you will sleep 250 and then while sleep 50

 

My last advise would be to say you to solve it yourself becose if you dont manage this you wont be able to manage anyscript that become big enouth to breack your brain ;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

7 minutes ago, IAMK said:

@caramen I think it is fairly simple to implement. Like I said before in one of his other threads I believe, call functions and use the return to determine if you exit or not.

I agree with you though.

Make him easy exemple so he can learn the Logic. 

Can be userfull to everyone 🧐

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    ;Loop 1
    Send("G*L")
    Send($oExcel.Application.Cells($a,1).Value)
    Send("/XTIM")
    Sleep(1000)
    Send("{ENTER}")
    Sleep(2000)
    _FileReadToArray ($file, $arlines)
        For $i = $arlines [0] To 1 Step - 1     ;Loop 2
        MsgBox (0,"", $arlines [$i])    ;This is just for me to see if it is reading the log file. I will not have it in the final script
        ;I want to add a check here. If text 'None Listed' is found then I want to exit this loop and go back to Start ()
        Next    ;To read next line bottom up
    Next    ; To go to Loop 1 once Loop 2 is done
Endif

Believe me, I am trying very hard. I have broken the script and creating it in pieces. The above script is working. But I cant figure out how to add a condition and exit loop 2 and go back to Loop1 once the condition is found

Link to comment
Share on other sites

If you While-While then you exitLoop you will start again at While : 

;Point A
While (1)
    ;Point B
    While (1) 
        If ... Then 
            ;Point C
            ExitLoop
        EndIf
        ExitLoop
    WEnd
WEnd

ExitLoop Bring you to "Point B" So you can make two while then exit Loop to back back at first while.

 

;Point A
While (1)
    ;Point B
    While (1) 
        If ... Then 
            ;Point C
            ExitLoop
        EndIf
        ExitLoop
    WEnd
    ExitLoop
WEnd
;Point D

This one bring you to "Point D"

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

14 minutes ago, caramen said:

If you While-While then you exitLoop you will start again at While : 

;Point A
While (1)
    ;Point B
    While (1) 
        If ... Then 
            ;Point C
            ExitLoop
        EndIf
        ExitLoop
    WEnd
WEnd

ExitLoop Bring you to "Point B" So you can make a while then exit Loop

My 'While' is a variable. I have modified the script based on your guidance, however the 'while' is not working since it is not fixed

Link to comment
Share on other sites

Do you know

Do ... until

?

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 minute ago, Vikramjeet said:

I will have to google. I am learning from experts like you :-) Is it possible to have a sample using Do....until

I am very far from expert statut... but i take that as a compliment. ^_^

just so you know... i never used

While ( $Var = 1 ) 

WEnd

Since for me 

Do

...

Until $Var = (Whatever i want  ) 

Is realy simple and can do the while statement more flexible for my brain. but it is pretty same i guess... 

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

  • Developers
2 minutes ago, caramen said:

but it is pretty same i guess.

The only difference is that the first one will do the loop evaluation at the beginning and the second at the end.Other than that there is no difference, so it really depends on the use-case. 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
    Send("G*L")
    Send($oExcel.Application.Cells($a,1).Value)
    Send("/XTIM")
    Sleep(1000)
    Send("{ENTER}")
    Sleep(2000)
    _FileReadToArray ($file, $arlines)
        For $i = $arlines [0] To 1 Step - 1
            If $arlines [$i] = "‡NONE LISTED" Then
                ExitLoop
            Endif
        Next
    Next
Endif
$oExcel.Application.Quit

Finally!!!! A piece is working. Now I need to add another loop. Thank you Caramen, I am sure I will need more help to finish this

Link to comment
Share on other sites

Yay !

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
    Send("G*L")
    Send($oExcel.Application.Cells($a,1).Value)
    Send("/XTIM")
    Sleep(1000)
    Send("{ENTER}")
    Sleep(2000)
    _FileReadToArray ($file, $arlines)
        For $i = $arlines [0] To 1 Step - 1 ;This loop counter is reading a log file bottom up and looking for text 'NONE LISTED'. I want it to go up only                                              ;5 lines to read the log file. Right now it goes till the top row every time
            If $arlines [$i] = "‡NONE LISTED" Then
                ExitLoop
            Endif
        Next
    Next
Endif
$oExcel.Application.Quit

Well, I already need help. The second loop counter is reading a log file bottom up and looking for text 'NONE LISTED'. I want it to go only up to 5 lines up to read the log file. Right now it goes till the top row every time. Any suggestions

Link to comment
Share on other sites

Correction.

How much lines you got in the file ?

Does this amount can change ?

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

There is no fixed number of lines. The script is reading a log file in real time and there is no way to know the amount of data that is returned to the log file. For this reason I am reading the file bottom up, and exit loop if the word 'NONE LISTED' is found. But now the problem is that search from bottom up does not end till it reaches the first line of the file. I need to stop that. i want the script to search from last line and move up only 5 lines

Link to comment
Share on other sites

Oh, ok. may you can
 

;logic help
$Rows = UBound ($MyReadedTextRows)

$TheLineIWant  = $Row - 5

Returns the size of array dimensions or the number of keys in a map.

An exemple of UBound not related to your goal :

$cHeight = _GUICtrlComboBoxEx_GetListArray ( $cCombo0002 );Return an array
$iRow = UBound ($cHeight);Getting amount
   If $cHeight[$iRow-1] = "Office" Then ;Comparing
   ;Nothing happen
   Else
   GUICtrlSetData($cCombo0002, Null )
   GUICtrlSetData($cCombo0002, "Forti|Blabla|Office")
   EndIf
;You can try this sample if you make a GuiComboList under the $variable = $cCombo0002

Or try the help file lol^^.

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

$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
    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
            $data = FileReadLine($file, $i)
            MsgBox(0,"", $data)
            If $data = "‡NONE LISTED" Then
            MsgBox (0,"", "Awesome")
            ExitLoop
            Endif
        Next
    Next
Endif
$oExcel.Application.Quit

Hey Caramen, I got the 2nd loop to work. It is working exactly how I want. Now time to add another loop :-(

Link to comment
Share on other sites

This is how to simplify with Function(If you make more and more loop :

 

When you know everything is working.

 

Start ()


Func Start ()
   If $hWnd Then
      For $a = 1 to $iCell    
      MyCondition ()
      Next
   Endif
$oExcel.Application.Quit
EndFunc

Func MyCondition ()
    Send("G*L")
    Send($oExcel.Application.Cells($a,1).Value)
    Send("/XTIM")
    Sleep(1000)
    Send("{ENTER}")
    Sleep(2000)
    Global $file = "DATA.log", $data = "" ;Notice i changed Local To Global so this $file will keep value in all other Function.
        $lines = _FileCountLines($file)
            MsgBox(0,"",$lines)
               For $i = $lines-4 To $lines
               $data = FileReadLine($file, $i)
               MsgBox(0,"", $data)
                  If $data = "‡NONE LISTED" Then
                  MsgBox (0,"", "Awesome")
                  ExitLoop
                  Endif
               Next
EndFunc

It is just an idea you can do everything as you want. This also mean you can reuse what you did if you need it again... ? You got it ?

 

Start ()


Func Start ()
   If $hWnd Then
      For $a = 1 to $iCell    
      MyCondition ()
      Next
   ElseIf 
      For $a = 150 to $iCell      
      MyCondition ()
      ;...MoreStuff
      ;Onemore loop/condition/blabla
      Next
   Endif
$oExcel.Application.Quit
EndFunc

Func MyCondition ()
    Send("G*L")
    Send($oExcel.Application.Cells($a,1).Value)
    Send("/XTIM")
    Sleep(1000)
    Send("{ENTER}")
    Sleep(2000)
    Global $file = "DATA.log", $data = "" ;Notice i changed Local To Global so this $file will keep value in all other Function.
        $lines = _FileCountLines($file)
            MsgBox(0,"",$lines)
               For $i = $lines-4 To $lines
               $data = FileReadLine($file, $i)
               MsgBox(0,"", $data)
                  If $data = "‡NONE LISTED" Then
                  MsgBox (0,"", "Awesome")
                  ExitLoop
                  Endif
               Next
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

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