Sign in to follow this  
Followers 0
Zen

Parsing a Text...

12 posts in this topic

OK, i need help. I'am a Nooby and have a idea, but i dont know how it works.

The Script copy a text i a File (or Anywhere) and check it to Part of a Text. Example:

This is Text One...

This is Text Two...

This is Text Four...

If in the text is the Word "Two" then make Msgbox(4096, "", "I have it found")

This Script runs all 10min.

You now what i mean?

Share this post


Link to post
Share on other sites



I just took part of Stumpii's Code from earlier today so I wouldn't have to write it all.

$Openfile = FileOpen("C:\test1.txt", 0)
$FirstWord = "two"

; Check if file opened for reading OK
If $Openfile = -1 Then
    MsgBox(0, "Error", "Unable to open Openfile .")
    Exit
EndIf

; Read in lines of text until the EOF is reached
$CurrentLineNumber = 1
While 1
    $line = FileReadLine($Openfile)
    If @error = -1 Then ExitLoop
    $FirstWordString = StringInStr($line, "two", 0, 1)
    MsgBox(0, "", "The word: " & '"' & $FirstWord & '"' & " was found")
    $CurrentLineNumber = $CurrentLineNumber + 1
WEnd

FileClose($Openfile)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

It doesn't work. When i tipp in the text1.txt a text without Two, then the msgbox comes too.

Share this post


Link to post
Share on other sites

It doesn't work. When i tipp in the text1.txt a text without Two, then the msgbox comes too.

<{POST_SNAPBACK}>

Err... maybe this is a silly question... but what message box comes up?

Did you create a text file for this test in your C: directory named test1.txt?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Ooops, my bad... try this (I never mess with file read much)

$Openfile = FileOpen("C:\test1.txt", 0)
$FirstWord = "two"

; Check if file opened for reading OK
If $Openfile = -1 Then
    MsgBox(0, "Error", "Unable to open Openfile .")
    Exit
EndIf

; Read in lines of text until the EOF is reached
$CurrentLineNumber = 1
While 1
    $line = FileReadLine($Openfile)
    If @error = -1 Then ExitLoop
    $strungit = String($line)
    $FirstWordString = StringInStr($strungit, "two")
    If $FirstWordString > 0 Then
    MsgBox(0, "", "The word: " & '"' & $FirstWord & '"' & " was found")
    $CurrentLineNumber = $CurrentLineNumber + 1
    EndIf
WEnd

FileClose($Openfile)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Yeah thanks. But now i need a Loop. This Script starts all 15min. You know how it works?

Share this post


Link to post
Share on other sites

Yeah thanks. But now i need a Loop. This Script starts all 15min. You know how it works?

<{POST_SNAPBACK}>

I'm sorry... I don't understand your question...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

ooo Sorry.

Global $Paused

AutoItSetOption("PixelCoordMode", 0)
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("MouseClickDownDelay", 0)
AutoItSetOption("MouseClickDelay", 0)
AutoItSetOption("WinTitleMatchMode", 3)
AutoItSetOption("WinWaitDelay", 300)

HotKeySet("{SPACE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

$AFFileOpen = FileOpen("AutoSave.txt", 2)
$AFWord = "TWO"

WinActivate("A Browserwindow", "")
    MouseClick("left", 100, 363, 1, 0)
    checkready()
    
    Send("^a")
    Sleep(25)
    Send("^c")
    FileWriteLine($AFFileOpen, ClipGet())


; Check if file opened for reading OK
If $AFFileOpen = -1 Then
    MsgBox(0, "Error", "AutoSave.txt nicht gefunden!")
    Exit
EndIf

; Read in lines of text until the EOF is reached
$CurrentLineNumber = 1
While 1
    $line = FileReadLine($AFFileOpen)
    If @error = -1 Then ExitLoop
    $strungit = String($line)
    $FirstWordString = StringInStr($strungit, "TWO")
    If $FirstWordString > 0 Then
    MsgBox(0, "", "The word: " & '"' & $AFWord & '"' & " was found", 10)
    $CurrentLineNumber = $CurrentLineNumber + 1
    EndIf
WEnd

FileClose($AFFileOpen)


Func checkready()
    MouseMove(500, 250, 1)
    Sleep(Int(Random(250, 400)))
    $cnt = 0

    Do
        Sleep(300)
        $cnt = $cnt + 1
        If $cnt > 100 Then
            Exit
        EndIf
    Until MouseGetCursor() = 2
EndFunc


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc


Func Terminate()
    Exit 0
EndFunc

The Script copy all 15min the ClipGet() and check then the Word. How i do this?

Share this post


Link to post
Share on other sites

You might want to look at StringRegExp for text matching instead of StringInStr. It can match more complex patterns.


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

Global $Paused

AutoItSetOption("PixelCoordMode", 0)
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("MouseClickDownDelay", 0)
AutoItSetOption("MouseClickDelay", 0)
AutoItSetOption("WinTitleMatchMode", 3)
AutoItSetOption("WinWaitDelay", 300)

HotKeySet("{SPACE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

While 1;<<<<<<<<<<<<<<<added
    Main_loop();<<<<<<<<<<<<<<<added
    Sleep(1000 * 60 * 15);<<<<<<<<<<<<<<<added
WEnd;<<<<<<<<<<<<<<<added

Func Main_loop();<<<<<<<<<<<<<<<added
    $AFFileOpen = FileOpen("AutoSave.txt", 2)
    $AFWord = "TWO"
    
    WinActivate("A Browserwindow", "")
    MouseClick("left", 100, 363, 1, 0)
    checkready()
    
    Send("^a")
    Sleep(25)
    Send("^c")
    FileWriteLine($AFFileOpen, ClipGet())
    
    
   ; Check if file opened for reading OK
    If $AFFileOpen = -1 Then
        MsgBox(0, "Error", "AutoSave.txt nicht gefunden!")
        Exit
    EndIf
    
   ; Read in lines of text until the EOF is reached
    $CurrentLineNumber = 1
    While 1
        $line = FileReadLine($AFFileOpen)
        If @error = -1 Then ExitLoop
        $strungit = String($line)
        $FirstWordString = StringInStr($strungit, "TWO")
        If $FirstWordString > 0 Then
            MsgBox(0, "", "The word: " & '"' & $AFWord & '"' & " was found", 10)
            $CurrentLineNumber = $CurrentLineNumber + 1
        EndIf
    WEnd
    
    FileClose($AFFileOpen)
EndFunc  ;==>Main_loop <<<<<<<<<<<<<<<added


Func checkready()
    MouseMove(500, 250, 1)
    Sleep(Int(Random(250, 400)))
    $cnt = 0
    
    Do
        Sleep(300)
        $cnt = $cnt + 1
        If $cnt > 100 Then
            Exit
        EndIf
    Until MouseGetCursor() = 2
EndFunc  ;==>checkready


Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc  ;==>TogglePause


Func Terminate()
    Exit 0
EndFunc  ;==>Terminate
Try the code above - if I understood your request correctly.

Do you have a use for the file named AutoSave.txt or are you just using it to stop on the web page that contains "TWO"? If you do not need the file named AutoSave.txt, then try the code below:

Global $Paused

AutoItSetOption("PixelCoordMode", 0)
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("MouseClickDownDelay", 0)
AutoItSetOption("MouseClickDelay", 0)
AutoItSetOption("WinTitleMatchMode", 3)
AutoItSetOption("WinWaitDelay", 300)

HotKeySet("{SPACE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

While 1
    Main_loop()
    Sleep(1000 * 60 * 15)
WEnd


Func Main_loop()
    WinActivate("A Browserwindow", "")
    MouseClick("left", 100, 363, 1, 0)
    checkready()
    
    Send("^a")
    Sleep(25)
    Send("^c")
    If StringInStr(ClipGet(), "TWO") > 0 Then
        MsgBox(0, "", "The word: " & '"' & $AFWord & '"' & " was found", 10)
        Exit
    EndIf
EndFunc  ;==>Main_loop


Func checkready()
    MouseMove(500, 250, 1)
    Sleep(Int(Random(250, 400)))
    $cnt = 0
    
    Do
        Sleep(300)
        $cnt = $cnt + 1
        If $cnt > 100 Then
            Exit
        EndIf
    Until MouseGetCursor() = 2
EndFunc  ;==>checkready


Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc  ;==>TogglePause


Func Terminate()
    Exit 0
EndFunc  ;==>Terminate
The script above just exits when the word "TWO" is found on the web page - change that as you need. There are other ways to accomplish this also...

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

The First looks great. Thanks a lot. But i dont unterstand where the loop is. And what are this:

;==>Main_loop

;==>checkready

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

...i dont unterstand where the loop is...

<{POST_SNAPBACK}>

I picked a poor name for the main function. Perhaps I should have called it main_function instead of calling it main_loop. The script has one main loop. It is this part:
While 1
    Main_loop()
    Sleep(1000 * 60 * 15)
WEnd
That part calls the main function and then just waits about 15 minutes and calls the main function again.

And what are this:

;==>Main_loop

;==>checkready

<{POST_SNAPBACK}>

Those are comments added by a nice program named Tidy. Tidy cleans up code in many ways. If you are going to write AutoIt code much, I would really encourage you to download the "AutoIt version of the SciTE editor". It comes with Tidy and much much more.

http://www.autoitscript.com/autoit3/scite/

edit:added the word "comments" to "Those are comments added by..."

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

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