Sign in to follow this  
Followers 0
Bizzet

Help With My Script?

15 posts in this topic

$i = 1

While 1
$file = FileOpen("name.txt", 0)
Sleep(100)
$read = FileReadLine($file, $i)
Sleep(100)
Send($read)
Sleep(1000)
Send("{ENTER}")
Sleep(1000)
PixelSearch(607, 432, 607, 432, 0xFFFFDD)
If @error Then
Send("{ENTER}")
Sleep(500)
Send("{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}")
Sleep(5)
ElseIf Not @error Then
MsgBox(0, "Name", "A NAME HAS BEEN FOUND!") Then ExitLoop
EndIf
If WinExists("Name") Then
Exit 0
EndIf
WEnd

Func end()
Exit 0
EndFunc

It only sends the first line over and over? How to improve to make it send line by line.?

Share this post


Link to post
Share on other sites



The reason it only reads one line is because you are not incrementing (counting) up any.

Your $i var always equals 1.

Add after Sleep(5)

$i += 1

And then see if that runs how you wanted it to.


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

The reason it only reads one line is because you are not incrementing (counting) up any.

Your $i var always equals 1.

Add after Sleep(5)

$i += 1

And then see if that runs how you wanted it to.

Thank you it works great

One more question.

ElseIf Not @error

Then MsgBox(0, "Name", "A NAME HAS BEEN FOUND!")

Then stop until I click okay, then continue on the same line it was on?

How would I do so?

(My friend made this code for me, I have no good knowledge about AutoIt3 sorry)

Share this post


Link to post
Share on other sites

Bizzet,

Welcome to the AutoIt Forums!

When opening a file with the command FileOpen() you should always release it when the script is done with the file with FileClose() so that any changed elements may be saved, and so that other resources may utilize the new information.

However I think there is a better way to achieve what you want here using arrays, its a quicker to read a file into an array than pass through a loop to do as you wish. I fixed a few other lines of code for you, hope this helps you with learning AutoIt :D

#include <File.au3>

Local $file_path = @ScriptDir & 'name.txt'
Local $aTextLines

_FileReadToArray( $file_path, $aTextLines ) ;this will read your file into a 1 dimensional array

For $i = 1 to UBound( $aTextLines ) - 1 ;this is to increment a loop
   Send($aTextLines[$i]) ;this will send the line read from file based on the increment that $i is at
   Sleep(1000)
   Send("{ENTER}")
   Sleep(1000)
   PixelSearch(607, 432, 607, 432, 0xFFFFDD)
   If @error Then
      Send("{ENTER}")
      Sleep(500)
      Send("{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}")
      Sleep(5)
   Else ; you didn't need the extra not @error here, because 'Else' is the opposite of If @error
      MsgBox(0, "Name", "A NAME HAS BEEN FOUND!") Then ExitLoop
   EndIf
   If WinExists("Name") Then ExitLoop
Next

Exit 0

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Bizzet,

Welcome to the AutoIt Forums!

When opening a file with the command FileOpen() you should always release it when the script is done with the file with FileClose() so that any changed elements may be saved, and so that other resources may utilize the new information.

However I think there is a better way to achieve what you want here using arrays, its a quicker to read a file into an array than pass through a loop to do as you wish. I fixed a few other lines of code for you, hope this helps you with learning AutoIt :D

#include <File.au3>

Local $file_path = @ScriptDir & 'name.txt'
Local $aTextLines

_FileReadToArray( $file_path, $aTextLines ) ;this will read your file into a 1 dimensional array

For $i = 1 to UBound( $aTextLines ) - 1 ;this is to increment a loop
   Send($aTextLines[$i]) ;this will send the line read from file based on the increment that $i is at
   Sleep(1000)
   Send("{ENTER}")
   Sleep(1000)
   PixelSearch(607, 432, 607, 432, 0xFFFFDD)
   If @error Then
      Send("{ENTER}")
      Sleep(500)
      Send("{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}")
      Sleep(5)
   Else ; you didn't need the extra not @error here, because 'Else' is the opposite of If @error
      MsgBox(0, "Name", "A NAME HAS BEEN FOUND!") Then ExitLoop
   EndIf
   If WinExists("Name") Then ExitLoop
Next

Exit 0

Thank you I have switched to your method. My current script is

Sleep(1000)
MouseMove(531, 235)
Sleep(100)
MouseClick("left")
#include <File.au3>
Local $file_path = @ScriptDir & 'name.txt'
Local $aTextLines
_FileReadToArray( $file_path, $aTextLines ) ;this will read your file into a 1 dimensional array
For $i = 1 to UBound( $aTextLines ) - 1 ;this is to increment a loop
   Send($aTextLines[$i]) ;this will send the line read from file based on the increment that $i is at
   Sleep(1000)
   Send("{ENTER}")
   Sleep(1000)
   PixelSearch(607, 432, 607, 432, 0xFFFFDD)
   If @error Then
      Send("{ENTER}")
      Sleep(500)
      Send("{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}")
      Sleep(5)
   Else ; you didn't need the extra not @error here, because 'Else' is the opposite of If @errttenuates

  MouseClick("left", 563, 469, 1)
  Sleep(10)
  MouseClick("left", 688, 236, 1)
  Sleep(10)
   MouseClick("left", 157, 455, 1)
   Sleep(10)
   MouseClick("left", 368, 318, 1)
   Sleep(10)
   EndIf
  
Next
Exit 0

After Else but before the mouse clicks how would I pause the script until the mouse clicks are done?

Thank you all once again.

Edited by Bizzet

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

After Else but before the mouse clicks how would I pause the script until the mouse clicks are done?

Thank you all once again.

I'm not sure what your asking here. Please give more details.

Pausing the script would stop any part of the script from functioning unless you were using an AdLib.

It almost sounds like your trying to automate a web page and want the script to wait for the new page before proceeding. If that is the case then you should be looking into the Library IE.au3 which is completely based on automating web pages. One function _IELoadWait() will wait for the page to completely load before executing the rest of the script. The functions in this library will provide more accurate clicks then MouseClick() will, such as _IELinkClickByText() or _IENavigate().

However if your wanting your script to wait for an application/program to change form/page. Then there are a few options there, such as WinWaitActive() which will pause your script until the title of the application window appears. If the title is the same on the original page as the one your waiting for you can include text to look for in the 2nd parameter of this function.

Hope this helps. If not please be more descriptive on what your attempting, what you hope to achieve, and what errors/problems your having.

Realm

Edit: Typos

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I'm not sure what your asking here. Please give more details.

Pausing the script would stop any part of the script from functioning unless you were using an AdLib.

It almost sounds like your trying to automate a web page and want the script to wait for the new page before proceeding. If that is the case then you should be looking into the Library IE.au3 which is completely based on automating web pages. One function _IELoadWait() will wait for the page to completely load before executing the rest of the script. The functions in this library will provide more accurate clicks then MouseClick() will, such as _IELinkClickByText() or _IENavigate().

However if your wanting your script to wait for an application/program to change form/page. Then there are a few options there, such as WinWaitActive() which will pause your script until the title of the application window appears. If the title is the same on the original page as the one your waiting for you can include text to look for in the 2nd parameter of this function.

Hope this helps. If not please be more descriptive on what your attempting, what you hope to achieve, and what errors/problems your having.

Realm

Edit: Typos

Yes it on a program. Let me explain further. When the 'else' part of the script started the mouseclicks it would continue to send the lines from the .txt causing other windows to open up and stopping me from achieving the end of the goal.

By 'else part' I mean

Else
  MouseClick("left", 563, 469, 1)
  Sleep(10)
  MouseClick("left", 688, 236, 1)
  Sleep(10)
   MouseClick("left", 157, 455, 1)
   Sleep(10)
   MouseClick("left", 368, 318, 1)
   Sleep(10)
Edited by Bizzet

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

When those windows appear what do you do with them?

If you close them, then you could use WinWaitActive() to wait for them to appear, then WinClose() to close them when they do.

Edit: Example

_CloseAnnoyingWindow('AnnoyingWindow1')
;Do Something
_CloseAnnoyingWindow('AnnoyingWindow2')
;Do Something

Func _CloseAnnoyingWindow($winTitle)
   WinWaitActive($winTitle, '')
   WinClose($winTitle,'')
EndFunc

Edit2: Changed Example for repetiveness

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

When those windows appear what do you do with them?

If you close them, then you could use WinWaitActive() to wait for them to appear, then WinClose() to close them when they do.

Sorry your not really understand what I mean.

The

Send($aTextLines[$i])

is interfering with

Else ; you didn't need the extra not @error here, because 'Else' is the opposite of If @errttenuates
  MouseClick("left", 563, 469, 1)
  Sleep(10)
  MouseClick("left", 688, 236, 1)
  Sleep(10)
   MouseClick("left", 157, 455, 1)
   Sleep(10)
   MouseClick("left", 368, 318, 1)
   Sleep(10)

I need to stop the loop of

Send($aTextLines[$i])

While The Following is clicking

Else ; you didn't need the extra not @error here, because 'Else' is the opposite of If @errttenuates
  MouseClick("left", 563, 469, 1)
  Sleep(10)
  MouseClick("left", 688, 236, 1)
  Sleep(10)
   MouseClick("left", 157, 455, 1)
   Sleep(10)
   MouseClick("left", 368, 318, 1)
   Sleep(10)

but resume reading on the same textline as it was on before it stopped.

The windows do not have names because they are built into the main window.

Edited by Bizzet

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Its impossible for the Send() function to interfere with the rest of the code....your code does not react all at once, it runs line by line. So it must have something to do with the application that your sending the text to. Some applications accept the send() data, yet take a few moments to fully input it. You will need to add a check to see when the application is ready to continue or a Sleep() function to wait for it to be ready.

Edit: Is there a light that turns on, or a message window popup, or some sort of indication that allows you to know when the Send() has completed it's job?

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Its impossible for the Send() function to interfere with the rest of the code....your code does not react all at once, it runs line by line. So it must have something to do with the application that your sending the text to. Some applications accept the send() data, yet take a few moments to fully input it. You will need to add a check to see when the application is ready to continue or a Sleep() function to wait for it to be ready.

Nowhere in the code does the loop stop? It continues until I close it.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

The Loop will stop after it has gone through all the lines of text from your file.

Edit: It should Send a line of text, the run the next optional of mouseclicks or your custom message window. It should not send the next line until after the mouseclicks have been done. If the mouseclicks are still moving while it sends the next line of text, then your application is lagging the mouseclicks. So you will need to set a Check for when the mouseclicks finish before it continues the script.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Oh I see how you didn't understand!

I'll lay it out in a better way.

The script starts to send each line of the .txt. After each line it checks to see if it got an error. If it doesn't get an error it should send the following line of text from the .txt. If it does get an error it should pause the sending and checking, simulate the mouse clicks, then continue sending and checking the following lines of text one by one. Not all the lines of text are done being processed when the mouse clicks are simulated and it causes an error.

Edited by Bizzet

Share this post


Link to post
Share on other sites

Evidently you don't see my understanding.

Your script should perform exactly as you wish, and just described.

What your not understanding is that I'm trying to tell you that the problem is in the application not the script. Some applications lag, some utilize their own engines to accept, interpret, and perform actions instructed by mouse and keyboard, thus your script may move to the next incremented level, while the application is still lagging while interpreting and performing the commands.

So what I have been trying to tell you, is that After your script utilizes the Else section of your script, you will need to add at the end some form of check or Sleep() function to allow your application to interpret and peform your actions before it moves to the next level.

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Alright well thanks for trying!

Looking for answers still.

I tried it out on Notepad and still not doing the correct functions.

Please read above for a better explanation!

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