Jump to content

Send 2 lines from text file


Recommended Posts

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
Link to comment
Share on other sites

  • Replies 46
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

$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- #
Link to comment
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

Link to comment
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

Link to comment
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?

Link to comment
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

Link to comment
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"?
Link to comment
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.

Link to comment
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?
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...