Sign in to follow this  
Followers 0
haXor4life

Send 2 lines from text file

47 posts in this topic

#1 ·  Posted (edited)

Please help me. I want to send 2 lines from a text file. And I want it to be repeated after pause but then it should be another two lines etc. Please help.

Or can you help in sending ANY AMOUNT OF INFOMATION from text file that goes beetwen certain symbols?

Edited by haXor4life

Share this post


Link to post
Share on other sites



BrettF, I added to my wish, can you help?

Share this post


Link to post
Share on other sites

$Text = FileRead("somefile.txt")
$Text = __StringBetween($Text, "PointA", "PointB")
MsgBox(0, "", $Text)

Func __StringBetween($s, $from, $to)
    $x = StringInStr($s, $from) + StringLen($from)
    $y = StringInStr(StringTrimLeft($s, $x), $to)
    Return StringMid($s, $x, $y)
EndFunc


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

I have helped.

You will need to produce some attempt before I even look at opening SciTE.

Not many here will do it for you. I for one prefer others that I help learn, from their mistakes, from what we tell them etc, and it improves their coding skills. No giving without receiving first :)

Cheers,

Brett

Share this post


Link to post
Share on other sites

Thank you for this example AzKay.

BrettF, I can make mouseclicks and sends but other things are hard.

There is a problem. I made this file

PointA

1

PointB

PointA

2

PointB

PointA

3

PointB

PointA

4

PointB

but code send only '1'.

How can I send leftover text?

Share this post


Link to post
Share on other sites

__StringBetween will only return the first found;

Try _StringBetween instead.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

__StringBetween will only return the first found;

Try _StringBetween instead.

It did the same thing.

Share this post


Link to post
Share on other sites

Shouldnt. As _StringBetween returns an array.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

Shouldnt. As _StringBetween returns an array.

So I wrote new code and it returned only '1'.

Share this post


Link to post
Share on other sites

#include <file.au3>
Dim $aRecords
If Not _FileReadToArray("file.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0] Step 2
    Send ($aRecords[$x])
    Send ($aRecords[$x + 1])
    Sleep (2000)
Next

Share this post


Link to post
Share on other sites

Also; Where is the "new code". Hard to see what to fix; when theres no code to fix.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#include <file.au3>
Dim $aRecords
If Not _FileReadToArray("file.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0] Step 2
    Send ($aRecords[$x])
    Send ($aRecords[$x + 1])
    Sleep (2000)
Next
Thank you, I have two questions.

I need 2 mouseclicks then sending a text and then 2 more mouseclicks, then pause. New cycle should be with same mouseclicks but sending new part of text. Why is my code don't work correctly.

MouseClick("left", 111, 222, 1)

MouseClick("left", 333, 444, 1)

#include <file.au3>

Dim $aRecords

If Not _FileReadToArray("file.txt",$aRecords) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

For $x = 1 to $aRecords[0] Step 2

Send ($aRecords[$x])

Send ($aRecords[$x + 1])

MouseClick("left", 234, 345, 1)

MouseClick("left", 456, 567, 1)

Sleep (2000)

Next

This code repeat final MCs forever.

Second question: how does this code know what to send? And how to tell it send for example 3 lines, then 2, then 5 etc?

Share this post


Link to post
Share on other sites

Also; Where is the "new code". Hard to see what to fix; when theres no code to fix.

Sorry, I just replaced '__StringBetween' with '_StringBetween'.

Share this post


Link to post
Share on other sites

Sorry, I just replaced '__StringBetween' with '_StringBetween'.

Might want to look at _StringBetween() in the helpfile.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

1) Look where the first mouse clicks are, and where the second set is. See a problem with repeating them?

2) The function _FileReadToArray outputs an array, where the array index[0] is the total, and using a for loop, we loop through every 2 lines (step 2) and send the text ($i, $i +1) contained in the array. Process increments $i, different part of the array.

Cheers

Brett

Share this post


Link to post
Share on other sites

1) Look where the first mouse clicks are, and where the second set is. See a problem with repeating them?

No.

I tried various variations of placing those MCs. Didn't help.

2) The function _FileReadToArray outputs an array, where the array index[0] is the total, and using a for loop, we loop through every 2 lines (step 2) and send the text ($i, $i +1) contained in the array. Process increments $i, different part of the array.

Cheers

Brett

Do you mean if insert some $i="PointA" and then in text file it will send between those "PointA"?

Share this post


Link to post
Share on other sites

1) It can't repeat if its not in a loop. Now go figure.

2) Lets output the array:

$aRecords[0] = 12
$aRecords[1] = PointA
$aRecords[2] = 1
$aRecords[3] = PointB
$aRecords[4] = PointA
$aRecords[5] = 2
$aRecords[6] = PointB
$aRecords[7] = PointA
$aRecords[8] = 3
$aRecords[9] = PointB
$aRecords[10] = PointA
$aRecords[11] = 4
$aRecords[12] = PointB

Now lets switch to the For Loop line:

For $x = 1 To $aRecords[0] Step 2

In english it is a loop, where $x will increment by the step. So in this case, every time the loop reaches "Next", it will increment the loop by 2. Then it tests if $x is greater than $aRecords[0], if it is, it continues the script.

If we outputed $x once every iteration loop it would look like so:

1
3
5
7
9
11

Each part of the array is accessed by an index (the bits in the []).

Try reading the script again with that knowledge and see if it makes more sense.

Share this post


Link to post
Share on other sites

1) It can't repeat if its not in a loop. Now go figure.

Thank you.

2) Lets output the array:

$aRecords[0] = 12
$aRecords[1] = PointA
$aRecords[2] = 1
$aRecords[3] = PointB
$aRecords[4] = PointA
$aRecords[5] = 2
$aRecords[6] = PointB
$aRecords[7] = PointA
$aRecords[8] = 3
$aRecords[9] = PointB
$aRecords[10] = PointA
$aRecords[11] = 4
$aRecords[12] = PointB

Now lets switch to the For Loop line:

For $x = 1 To $aRecords[0] Step 2

In english it is a loop, where $x will increment by the step. So in this case, every time the loop reaches "Next", it will increment the loop by 2. Then it tests if $x is greater than $aRecords[0], if it is, it continues the script.

If we outputed $x once every iteration loop it would look like so:

1
3
5
7
9
11

Each part of the array is accessed by an index (the bits in the []).

Try reading the script again with that knowledge and see if it makes more sense.

Thank you. So I can't make some marks in text and then send text which is between marks?

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