Jump to content

repeating/looping


Recommended Posts

Hello guys, i maded a program which reads a number from an aplication and it uses those numbers to have a specific web adress were it reads how many pass or fails it has depends on the way i setted.

But i have one problem i don't know how to make him repeat himself

I added 3 loops so that in the first loop cleans the temp txt file were it stores the data from the web and after that it gets the number; The second thing i did i addes a if condition if it reads or not that number, if not it goes to sleep (pause) and waits to get the number ( i added the msgbox to see if it works hehe).

At the second loop i added the webadress from where to get the data specific to that number and stores it in a temp file.txt it open it.

The third loop is for guictrlsetdata so it can show me how many times has bin pass or failed (depending on how do i set it)

And the fourth loop is for counting how many times has bin pass or failes the same... depening on how do i set it.

My problem is i don;t know how to make it in such a way that after it finds out how many times is passed or failes to exit that loop and wait again to show him a number from that aplication or the same number.

Can you guys give me some clue's ?

I was thinking to add exitloop after Guictrlsetdata but that only shows me that the code has bin scanned once cause it repeats it self and it reads only once.

#include <IE.au3>
#include<file.au3>
#include <array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Form1", 275, 237, 451, 210)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 273, 233, BitOR($ES_CENTER,$ES_WANTRETURN))
;GUICtrlSetData(-1, "edit1")
GUISetState(@SW_SHOW)

while 1 ; first loop
    FileDelete("TEMP.TXT")
    msgbox(0,"First loop","1")
    ControlEnable("GUI v2.7.0.0","","WindowsForms10.BUTTON.app.0.378734a1")
    $b = ControlGetText("GUI v2.7.0.0","","WindowsForms10.BUTTON.app.0.378734a1")
    $test = StringTrimLeft($b,13)
    $test2 = StringTrimRight($test,1)
    msgbox(0,"asd",$test2)
    if $test2 = 0 Then ; cu asta cica ar trebui sa fi rezovlat problema la infint loop pentru a cauta codul 
        msgbox(0,"error","nu am gasit codul bsn")
        sleep(500)
    Else
        msgbox(0,"asd","am gasit codul bsn")
            $oIE = _IECreate("http://intranetadress.ro/checkid="&$test2,0,0)
            $sText = _IEBodyReadText ($oIE)
            filewrite("Temp.txt",$stext)
            $file = FileOpen("temp.txt", 0)
            msgbox(0,"asd","am deschis fisierul temp")
                while 1
                    while 1
                        ;msgbox(0,"asd","al 4 loop")
                        dim $a
                        $line = FileReadLine($file)
                        If @error = -1 Then ExitLoop
                        ;$stanga = StringTrimLeft($line,40)
                        $dreapta = StringTrimRight($line,105) 
                        ;msgbox(0,"asd",$dreapta) 
                        if $dreapta = "PASS" then 
                            $a += 1
                            exitloop
                        EndIf
                
                
                    WEnd
                sleep(200)

                Guictrlsetdata($Edit1,"I seens this thing for this many times:"&$a)
                
                wend

            
        
            
            
        
    endif
WEnd
Link to comment
Share on other sites

  • Moderators

mircea,

Why use a temp file? You can just convert the webpage into an array - it makes it much simpler. ;)

Here is an amended script - I have set up a couple of dummy variables to substitute for the web button text and web page so that you can see how it works (the ######## lines):

#include <IE.au3>
#include<file.au3>
#include <array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiEdit.au3>

$Form1 = GUICreate("Form1", 275, 237, 451, 210)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 273, 233, BitOR($ES_CENTER, $ES_WANTRETURN))
;GUICtrlSetData(-1, "edit1")
GUISetState(@SW_SHOW)

While 1 ; first loop

    ; Read from website
    ControlEnable("GUI v2.7.0.0", "", "WindowsForms10.BUTTON.app.0.378734a1")
    $b = ControlGetText("GUI v2.7.0.0", "", "WindowsForms10.BUTTON.app.0.378734a1")

    ; Adjust result
    $test = StringTrimLeft($b, 13)
    $test2 = StringTrimRight($test, 1)
    ;MsgBox(0, "asd", $test2)

    ; Simulate the web button text
    $test2 = 1 ; #######################################################################

    ; Test result
    If $test2 = 0 Then ; with that they say should be rezovlat problem to search infinite loop code
        ; Error
        MsgBox(0, "error", "I not found code BSN")
        Sleep(500)
    Else
        ; Success
        MsgBox(0, "asd", "I found code BSN")
        
        ; Open website
        ;$oIE = _IECreate("http://intranetadress.ro/checkid=" & $test2, 0, 0)
        ; Read webpage
        ;$sText = _IEBodyReadText($oIE)
        
        ; Simulate the web page text
        $sText = "PASS" & @CRLF & "PASS" & @CRLF & "PASS" & @CRLF & "PASS" ; #######################################################################

        ; get text into an array
        $aText = StringSplit($sText, @CRLF, 1)
        ; Display it so you can see what you get - this is only to demonstrate
        _ArrayDisplay($aText)

        ; Set count to 0
        $a = 0

        ; Loop through array elements
        For $i = 1 To $aText[0]
            $dreapta = $aText[$i] ;StringTrimRight($aText[$i], 105) ; Changed because the text is not what you woudl normally get
            If $dreapta = "PASS" Then
                $a += 1
                ;ExitLoop ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Why?  You want to keep counting!
            EndIf
        Next
        Sleep(200)

        ; Announce result
        ; GUICtrlSetData ; This replaces the text, you need to keep adding!
        _GUICtrlEdit_AppendText ($Edit1, "PASS was found " & $a & " times" & @CRLF)

    EndIf
WEnd

i hope the comments are clear - please ask if not. :huh2:

One thing - you may need to check on how the webpage writes EOL and adjust the Stringsplit parameter to match. :alien:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I can't user the stringsplit cause the text i want to search for it's different and i want just a specific one for example

this-ispass-a,

this-ispass-b,

this-ispass-c,

thats why i used stringtrimleft and stringtrimright cause when i want to search the programm to find out the specific one i searched.

Hmmm i don't know how to convert the webpage into array, cause the _iexplore commands are a bit confusing for me cause i must find some element's and i don't know how.

The reason why i used guictrlsetdata cause i only want to update once the data and do not show over and over again .

ex:

Pass:1

pass:2

pass:3

i only want him to show me once that thing.

pass:3

My issue is i don't know how to make it in such a way that after he finish counting how many times has bin count it to go over again to controlenable controlgettext and so on

Edit:

you have 7777 post :huh2:) that is cool

Edited by mircea
Link to comment
Share on other sites

  • Moderators

mircea,

You could use StringRegExp to look for and count the number of "PASS/FAIL" texts - then you do not have to worry about arrays. ;)

Could you please post whatever you get as a return from the page you are trying to parse and point out which bits you are trying to find. :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

And what do you want to get from that array?

I see you have a screenshot - why don't you indicate on that image the values you want?

I tried to undesrand what are you after and I couldn't.

Are you trying to say that $test2 has the value you want to search in the array? $test2 and "pass"?

Post here at least 2 complete lines and show what information exactly you are looking for - also, post an example of a full line which does NOT have the information you want. Your Array Display does not show the full text.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • Moderators

mircea,

enaiman is quite right - that _ArrayDisplay dialog is useless as it does not show the text we are supposed to be looking for. Use FileWrite to save the content of the webpage to a file and then upload that. :huh2:

We also need a clear example of what it is you are looking for in the line. Is it just the word "PASS/FAIL" or are there any paticular surrounding characters?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

mircea,

So you wish to count the number of CFTPASS or CFTFAIL in that text? :huh2:

If so then it is as easy as this:

StringReplace($sText, "CFTPASS", "")
ConsoleWrite("There are " & @extended & " CFTPASS" & @CRLF)
StringReplace($sText, "CFTFAIL", "")
ConsoleWrite("There are " & @extended & " CFTFAIL" & @CRLF)

Or is it a bit more complex than that. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yes that was my propuse to count, recheck the code, count it again, recheck the code (if i didn't change the code) and so on. I was thinking in the first place it was an algorithm mistake .But how do i make the Stringreplace insert into guictrlsetdata?

Thank you for your help

Edited by mircea
Link to comment
Share on other sites

  • Moderators

mircea,

Like this:

StringReplace($sText, "CFTPASS", "")
$iPass = @extended
StringReplace($sText, "CFTFAIL", "")
GuiCtrlSetData($Edit1, "There are " & $iPass & " passes" & @CRLF & "There are " & @extended & " fails")

All clear? :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yes, but i want to learn something from this. I can use stringreplace to find a specific text from anywere i search (i mean a text file)? And then at what is good Stringtrimright or left ? Cause once i used to another aplication that to find a specific word in a text file and it work.

And why it dosen't work in this way(i tried but it give's me the full txt file) $example = Stringreplace($sText, "CFTPASS","") ?

And thank you so much for the help

Link to comment
Share on other sites

  • Moderators

mircea,

i want to learn something from this

Good! :alien:

StringReplace will, as its name suggests, replace strings. But for it to work, you have to assign the result to another variable - like this:

$sText = "testFREDtestFREDtest"

; Assign the result of the replace
$sNewText = StringReplace($sText, "FRED", "ANNE")

; And show the new string
MsgBox(0, "Result", $sNewText & @CRLF & @CRLF & @extended & " replacements were made")

Note that the number of replacements is returned in @extended.

Now your original string is unaffected by this, so you can use StringReplace to count the number of times a sub-string exists in a string like this:

$sText = "testFREDtestFREDtest"

; No need to assign the result
StringReplace($sText, "FRED", "ANNE")

; The original remains untouched - and the count is still returned in @extended
MsgBox(0, "Result", $sText & @CRLF & @CRLF & "FRED was found " & @extended & " times")

We just discard the changed string. ;)

All clear now? :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hmmm, yes this is absolutley genius, damn and when i think was using fileread or _filelisttoarray to find the information.

Thank you very much for the help this gave me some ideas on my future projects.

Link to comment
Share on other sites

  • Moderators

mircea,

Glad I could help! :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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