Sign in to follow this  
Followers 0
arminius

selective reader then writer

18 posts in this topic

ok, what I'm trying to do is write a program that will see a specific text like "it's a beautiful day"

and if it reads that will write "let's go outside"

I have FileReadLine down for reading the text

but I'm having trouble with the IF text is "it's a beautiful day" then send text "let's go outside" part

Share this post


Link to post
Share on other sites



StringCompare

Compares two strings with options.

StringCompare ( "string1", "string2" [, casesense] )

Return Value

0 string1 and string2 are equal

> 0 string1 is greater than string2

< 0 string1 is less than string2

Example

$result = StringCompare("MELÓN", "melón")

MsgBox(0, "StringCompare Result (mode 0):", $result)

$result = StringCompare("MELÓN", "melón", 1)

MsgBox(0, "StringCompare Result (mode 1):", $result)

$result = StringCompare("MELÓN", "melón", 2)

MsgBox(0, "StringCompare Result (mode 2):", $result)

Share this post


Link to post
Share on other sites

What he meant was what is the code that you used, not what the helpfile said. If we can see how you used the code we might find an error in your usage.

Share this post


Link to post
Share on other sites

my code is very light cause I'm not sure how to proceed with the fundamentals, and the fundemental part is that when autoit copies text when it says readfileline, how can it search for specific text within the text it's just read?

for example

say it copy's "AutoIt Forums > AutoIt v3 > General Help and Support > selective reader then writer"

how can I tell auto it to seach for specificly "General Help and Support" within that text?

I'm sure from that point I can send specific key strokes where I want them, but it's that first part of if said text is found then do this that's got me stumped?

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

arminius

This?

$string = "my code is very light cause I'm not sure how to proceed" & @LF & _
          "AutoIt Forums > AutoIt v3 > General Help and Support > selective reader then writer" & @LF & _
          "with the fundamentals, and the fundemental part is that when autoit"
          
$aRead = StringRegExp($string, "(?i)(General Help and Support)", 1)
If @error Then
    MsgBox(64, "Message", "Required string not found!")
    Exit
EndIf

ConsoleWrite("---> Search result: " & $aRead[0] & @LF)
Edited by rasim

Share this post


Link to post
Share on other sites

arminius

This?

$string = "my code is very light cause I'm not sure how to proceed" & @LF & _
          "AutoIt Forums > AutoIt v3 > General Help and Support > selective reader then writer" & @LF & _
          "with the fundamentals, and the fundemental part is that when autoit"
          
$aRead = StringRegExp($string, "(?i)(General Help and Support)", 1)
If @error Then
    MsgBox(64, "Message", "Required string not found!")
    Exit
EndIf

ConsoleWrite("---> Search result: " & $aRead[0] & @LF)
I believe what he was after was a program that reads what is typed, then changes it... so if I type 'your hot' it will replace the word 'hot' with 'beautiful' or something along those lines...

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites

it's alot more complicated then I'm used to

well it's close, but rather then display an error when it doesn't find what it's looking for

I was wanting it to send keystrokes when it does find what it wants?

Share this post


Link to post
Share on other sites

it's alot more complicated then I'm used to

well it's close, but rather then display an error when it doesn't find what it's looking for

I was wanting it to send keystrokes when it does find what it wants?

use _ispressed() and have it say up to a certain amount of characters in memory...then

if _InString("whatever") then

send("{BS}" $AmountOfLettersInTheWord)

send("New Word")

endif

kind of simple, kind of, as long as the user doesnt keep typing it will work :) lol


[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites

no ReaImDown, that's not at all what I'm trying to do

I just want it to copy from a text file a line of text, if it finds something it's looking for it will send completely different text on somewhere

if it doesn't find any text it's been told to watch out for then it does nothing.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

no ReaImDown, that's not at all what I'm trying to do

I just want it to copy from a text file a line of text, if it finds something it's looking for it will send completely different text on somewhere

if it doesn't find any text it's been told to watch out for then it does nothing.

I am sorry, I misunderstood then :) I have a bad habbit of skimming articles lol,

just quickly edit Rasim's coding... and it will work fine...I will see if I can do it, after I get my girlfriend from school, that is if no1 has done it for you already, I never tried this before, but I imagine its quite simple

Edited by ReaImDown

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites

I am sorry, I misunderstood then :) I have a bad habbit of skimming articles lol,

just quickly edit Rasim's coding... and it will work fine...I will see if I can do it, after I get my girlfriend from school, that is if no1 has done it for you already, I never tried this before, but I imagine its quite simple

lazy lazy people haha, heres your solution...

test.txt

I am a string
this is a nice string
this string has a nice @$$

example.au3

$file = FileOpen("test.txt", 0)
global $txt = "", $Look4 = "string"
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    $txt = ($txt & $chars)
Wend
$result = StringInStr($txt, $Look4)
if $result <> 0 then
$a =    StringReplace($txt,$Look4,"bitch!")
MsgBox(0, "Search result:", $a)
endif
FileClose($file)

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites

I'm sorry, I thank u for trying, but I'm a newb, I'm trying to learn, I want to learn but I have no idea what that code is looking for, I put bitch! in the test.txt but it came up with nothing?

Share this post


Link to post
Share on other sites

I'm sorry, I thank u for trying, but I'm a newb, I'm trying to learn, I want to learn but I have no idea what that code is looking for, I put bitch! in the test.txt but it came up with nothing?

That's because the code he wrote wasn't looking for "bitch!" it was looking for "string" and will replace it with "bitch!"

$file = FileOpen("test.txt", 0)
global $txt = "", $Look4 = "string";<----- $Look4 is the string that's being searched for
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    $txt = ($txt & $chars)
Wend
$result = StringInStr($txt, $Look4);<----$txt is the text from the file, and $Look4 is the string to look for
if $result <> 0 then
$a =    StringReplace($txt,$Look4,"bitch!");<-----$this says replace anything in $txt/the text file, that matches $Look4 or string, and replace it with bitch!
MsgBox(0, "Search result:", $a)
endif
FileClose($file)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

That's because the code he wrote wasn't looking for "bitch!" it was looking for "string" and will replace it with "bitch!"

$file = FileOpen("test.txt", 0)
global $txt = "", $Look4 = "string";<----- $Look4 is the string that's being searched for
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    $txt = ($txt & $chars)
Wend
$result = StringInStr($txt, $Look4);<----$txt is the text from the file, and $Look4 is the string to look for
if $result <> 0 then
$a =    StringReplace($txt,$Look4,"bitch!");<-----$this says replace anything in $txt/the text file, that matches $Look4 or string, and replace it with bitch!
MsgBox(0, "Search result:", $a)
endif
FileClose($file)
sorry, didnt have time to sit there and comment on it, I was in a rush, girlfriend and my parents were waiting on me lol

updated code...added $ReplaceWith

$file = FileOpen("test.txt", 0)
global $txt = "", $ReplaceWith = "bitch!", $Look4 = "string";<----- $Look4 is the string that's being searched for
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    $txt = ($txt & $chars)
Wend
$result = StringInStr($txt, $Look4);<----$txt is the text from the file, and $Look4 is the string to look for
if $result <> 0 then
$a =    StringReplace($txt,$Look4,$ReplaceWith);<-----$this says replace anything in $txt/the text file, that matches $Look4 or string, and replace it with bitch!
MsgBox(0, "Search result:", $a)
endif
FileClose($file)
Edited by ReaImDown

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites

ok thanks guys :P it's still not quite what I was wanting it to do :P but I think I can experiment with what's there and get it to work :), thanks for all your help

Share this post


Link to post
Share on other sites

ok thanks guys :P it's still not quite what I was wanting it to do :D but I think I can experiment with what's there and get it to work :), thanks for all your help

np, give a shout back if I can be of more assistance, thought that was what you wanted though :P enjoy...gl


[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

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