Jump to content
Sign in to follow this  
CrewXp

Highlight names that appear in a seperate txt list

Recommended Posts

This is a seperate idea from my first post. But I'm working on a script that Indexes something in a text document. Is there a way for AutoIt to open a text file that say has 200 people's names separated line by line. Then in the program the book is in, the user select a text box. Then AutoIt search's the master list of people and if in that text box there's a name of someone in that list, it highlight's it.

Please don't confuse this topic with my first one. I still would like the other one answered. Thx

Share this post


Link to post
Share on other sites

_FileReadToArray() will be alot of help.

In addition, you could do a style of 'For/Next $Count = 1 To' 'number of names', 'If StringInStr'


Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Share this post


Link to post
Share on other sites

_FileReadToArray() will be alot of help.

In addition, you could do a style of 'For/Next $Count = 1 To' 'number of names', 'If StringInStr'

<{POST_SNAPBACK}>

Hmm.. I've seen that command but am not familiar with it. Can you provide an example?

Say I have a list of 2,400 names: Each line with a Firstname then Lastname

In the program, I click the text box, then click a GUI button, then autoit, selects all the text, searches the file for a name in that. Then if it finds something, Auto it highlights the name in the program then hits the designated key-combo to Index it. How can this be done with that command?

thx

Share this post


Link to post
Share on other sites

Hmm.. I've seen that command but am not familiar with it. Can you provide an example?

Say I have a list of 2,400 names: Each line with a Firstname then Lastname

In the program, I click the text box, then click a GUI button, then autoit, selects all the text, searches the file for a name in that. Then if it finds something, Auto it highlights the name in the program then hits the designated key-combo to Index it. How can this be done with that command?

The quick answer is Yes, you should be able to design a script with AutoIt3 that does everything you specified.

The UDF _FileReadToArray does part of what you need. That is, it reads the data file and puts each line in an array that the script can use. This UDF can be found in the help file.

The example below does some of what you are asking, but none of the GUI (that's another matter, but do-able), and is more inline with your original post. It works similar to the other script you are working on. That is, it uses a hot key to initiate the pick at the cursor location. To use, position the mouse over the name you want to check and press function key F2. It looks up the name and tell you if it found it or not (only the 1st matching name is identified). Keep doing that until you want to exit, at which time press the ESC key. I did not bother with prompts (use whichever technique you decide to use in your other script).

; Read the names for the data file
Dim $sFile = "c:\test.txt";<<<<< as desired.

; To select the name and look it up
HotKeySet("{F2}", "_LookUpName")
; To stop the script.
HotKeySet("{ESC}", "_Exit")

Global $sNames = FileRead($sFile, (FileGetSize($sFile)))
$sNames = StringReplace($sNames, @CRLF, "|")
$sNames = StringReplace($sNames, @LF, "|")
$sNames = StringReplace($sNames, @CR, "|")
$sNames = StringReplace($sNames, "||", "|")
Global $aNames = StringSplit($sNames, "|")
Global $sFullName = "", $sSirName = ""
; Keep script running until ESC is pressed.
While 1
  ; Press F2 to copy name under cursor, and then look it up.
  ; Press ESC to exit the script.
    If  $sFullName = -1 Then
        MsgBox(4096, "", 'No match for name: "' & $sSirName & '"')
        $sFullName = ""
    ElseIf $sFullName <> "" Then
        MsgBox(4096, "", '"' & $sFullName & '" was selected...')
        $sFullName = ""
    EndIf
WEnd
Exit

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _LookUpName()
; Look up the name
   Local $aPos[2]
   opt ("MouseCoordMode", 0)
   $aPos = MouseGetPos()
  ; Select the word under the cursor.
   MouseClick("left", $aPos[0], $aPos[1], 2, 1)
   Sleep(15)
  ; Copy the highlighted word
;~ Note: Could not get Send ^C to work properly,
;~ so use "edit" "copy" from menu.
  ;Send("^C", 0)
   Send("!EC", 0)
   Sleep(15)
   Send("{RIGHT}")
   Sleep(15)
   $sSirName = ClipGet()
  ; Check for a matching name
    $sFullName = -1
   If StringInStr($sNames, $sSirName) Then
      $i = -1
      While 1
        ; Name match, get first and sir name.
         $i = $i + 1
         If StringInStr($aNames[$i], $sSirName) Then
                $sFullName = $aNames[$i]
                ExitLoop
            Endif
      WEnd
   EndIf
EndFunc  ;==>_LookUpName

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _Exit()
   Exit
EndFunc  ;==>_Exit

Phillip

Share this post


Link to post
Share on other sites

I've tried the script and the coding looks great. But In the program's text box, it can't copy it unless I click in the text box. Then it copies the line! Awesome! But it says No match found in the file. What I did to text it is copy the entire text box contents into that list and then save it. Well it still couldn't find a match.

I've even tried just puttin the line that it couldn't find in the file and still no!

What could be the problem? Thx

Share this post


Link to post
Share on other sites

I've tried the script and the coding looks great. But In the program's text box, it can't copy it unless I click in the text box. Then it copies the line! Awesome! But it says No match found in the file. What I did to text it is copy the entire text box contents into that list and then save it. Well it still couldn't find a match.

I've even tried just puttin the line that it couldn't find in the file and still no!

What could be the problem? Thx

<{POST_SNAPBACK}>

Difficult to know, but:

1. I assume you changed the name of the data file from "c:\test.txt" to the name you are using, but I'll mention it just in case.

2. Is the text document a real "text" file? That is, not a word processor file. Can it be opened in Notepad?

3. Can you post a few sample lines from the data file, as well as the line that won't match. If it proprietary date, just make something up but in the same format as the real data. Here's the data I used for testing:

Bluto

Jane Doe

Mickey Mouse

Minnie Mouse

Popeye the Sailor

John Smith

John Wayne

4. What is the name of the data file? Does the path or file name have spaces in them (although I tested this and it does not seem to matter)?

5. If the data file is updated while the script is running, the script will not see the new data as the file is read only once. If that's the case, change the script to read the data file each time F2 is pressed.


Phillip

Share this post


Link to post
Share on other sites

This isn't regarding the main problem, I just noticed in the script you commented that you couldn't get Send( "^C" ) to copy. Change the 'C' to 'c' (lowercase) and it should work better.

As for the rest of the script, I can't yet figure out why, but when I use it, it always gives me the "No match for name: " MsgBox

Share this post


Link to post
Share on other sites

This isn't regarding the main problem, I just noticed in the script you commented that you couldn't get Send( "^C" ) to copy.  Change the 'C' to 'c' (lowercase) and it should work better.

As for the rest of the script, I can't yet figure out why, but when I use it, it always gives me the "No match for name: " MsgBox

<{POST_SNAPBACK}>

Thanks falconv. I forgot about that. It works much cleaner using ^c instead of my work around.

Phillip

Share this post


Link to post
Share on other sites

okay, I realize my mistake yesterday. I had the file open that I was checking against (apparently the script couldn't get the contents of the file while it's open). So this time I used a different file with the same names.

This time the problem I got is that it kept the first name (so I press F2, it selects and copies name1 and returns "name1 was selected...", but then I press F2 over name2, and it says "name1 was selected..." and does the same name no matter who's selected and no matter how many times I do it.

I'll investigate this, and if I find anything, I'll write back. :lmao:

Thanks a lot, phillip123adams

p.s. I just found out that the problem is that it only puts it in the clipboard the first time. If I manually put something in the clipboard, it doesn't get overwritten by the script, but gives MsgBox "phillip123adams was not found"

Share this post


Link to post
Share on other sites

okay, I realize my mistake yesterday.  I had the file open that I was checking against (apparently the script couldn't get the contents of the file while it's open).  So this time I used a different file with the same names.

This time the problem I got is that it kept the first name (so I press F2, it selects and copies name1 and returns "name1 was selected...", but then I press F2 over name2, and it says "name1 was selected..." and does the same name no matter who's selected and no matter how many times I do it.

I'll investigate this, and if I find anything, I'll write back.  :lmao:

Thanks a lot, phillip123adams

p.s.  I just found out that the problem is that it only puts it in the clipboard the first time.  If I manually put something in the clipboard, it doesn't get overwritten by the script, but gives MsgBox "phillip123adams was not found"

<{POST_SNAPBACK}>

That's very strange! Or is it? I just did a bunch of experiments and found that if I click on the name and then quickly press F2, the clipboard does NOT update. However, if I wait a moment after clicking on the name and then press F2, all is well. Could this be the problem?

If the above does not work:

Other than that, it works every time for me, even if I have the data file open or if I pick the names from somewhere else. I'm wondering if the script needs a small sleep here and there. For example, increase the sleep time after the mouse click that selects the name.

Below is a revised copy of the concept script. It creates a text file in the temporary directory, writes names to the files, and opens the file in Notepad. In addition, I added a couple of sleeps, and some message boxes to trap what happens at several locations. Please give this a test, and pick the names from the Notepad window.

; Read the names for this data file
Dim $sFile = @tempdir & "\test.txt";<<<<< filename as desired.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; testing only
;; Create the data file for testing
$hFile = FileOpen($sFile, 2)
Filewriteline($hFile, "Bluto")
Filewriteline($hFile, "Jane Doe")
Filewriteline($hFile, "Micky Mouse")
Filewriteline($hFile, "Minnie Mouse")
Filewriteline($hFile, ""); a blank line
Filewriteline($hFile, "Popeye the Sailor")
Filewriteline($hFile, "John Smith")
Filewriteline($hFile, "John Wayne")
FileClose($hFile)
Run("NotePad.exe " & $sFile)
sleep(500)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; testing only


; To select the name and look it up
HotKeySet("{F2}", "_LookUpName")
; To stop the script.
HotKeySet("{ESC}", "_Exit")

Global $sNames = FileRead($sFile, (FileGetSize($sFile)))
$sNames = StringReplace($sNames, @CRLF, "|")
$sNames = StringReplace($sNames, @LF, "|")
$sNames = StringReplace($sNames, @CR, "|")
$sNames = StringReplace($sNames, "||", "|")
Global $aNames = StringSplit($sNames, "|")
Global $sFullName = "", $sSirName = ""

; should display each line, separated with pipes (|).
MsgBox(4096, "Debug 0", "The file should be open in Notepad, and the next line should be the names from the file." & @lf & @lf & $sNames)

; Keep script running until ESC is pressed.
While 1
  ; Press F2 to copy name under cursor, and then look it up.
  ; Press ESC to exit the script.
   If $sFullName = -1 Then
      MsgBox(4096, "Debug 4", 'No match for name: "' & $sSirName & '"')
      $sFullName = ""
   ElseIf $sFullName <> "" Then
      MsgBox(4096, "Debug 5", '"' & $sFullName & '" was selected...')
      $sFullName = ""
   EndIf
WEnd
Exit


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _LookUpName()
  ; Look up the name
   Local $aPos[2]
   opt ("MouseCoordMode", 0)
   $aPos = MouseGetPos()
  ; Select the word under the cursor.
   MouseClick("left", $aPos[0], $aPos[1], 2, 1)
   Sleep(15)
sleep(100); <<<<<<<<<<<<<<<<<<<<<<<< Try a longer sleep here
  ; Copy the highlighted word (must be lowercase "c")
  ; Send("^C", 0); does not work because "C" is uppercase
  ; Send("!EC", 0); works, but slow
   Send("^c", 0)
   Sleep(15)
   Send("{RIGHT}{Left}")
   Sleep(15)
sleep(100); <<<<<<<<<<<<<<<<<<<<<<<< Try a longer sleep here
   $sSirName = ClipGet()
MsgBox(4096, "Debug 1", '$sSirName (the picked name) = "' & $sSirName & '"' & @lf & @lf & $sNames)
  ; Check for a matching name
   $sFullName = -1
   If StringInStr($sNames, $sSirName) Then
      $i = -1
      While 1
        ; Name matched, get first and sir name.
         $i = $i + 1
         If StringInStr($aNames[$i], $sSirName) Then
            $sFullName = $aNames[$i]
            ExitLoop
         EndIf
      WEnd
MsgBox(4096, "Debug 2", '$sSirName (the picked name) = "' & $sSirName & '"' & @lf & $sFullName & @lf & @lf & $sNames)
   Else
MsgBox(4096, "Debug 3", '"' & $sSirName & '" not found in ' & @lf & @lf & $sNames & '.')
   EndIf
EndFunc  ;==>_LookUpName

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _Exit()
   Exit
EndFunc  ;==>_Exit

Phillip

Share this post


Link to post
Share on other sites

phillip your the man. It works. When I change /text.txt to the file path, it comes with an error now. How do I make it select the file. Also when it says blah selected, it doesn't actually select the name. No highlights visible. Is that how its suposed to be.

And thanks again john, your a genious at this!

Share this post


Link to post
Share on other sites

CrewXP,

@post #13:

It works. When I change /text.txt to the file path, it comes with an error now. How do I make it select the file. Also when it says blah selected, it doesn't actually select the name. No highlights visible. Is that how its suposed to be.

I need more information:

1. What suggestion(s) solved, or seemed to solve, the problem?

2. What is the error you are getting?

3. You refer to "/text.txt". Are you substituting forward slashes (/) for back slashes (\) in the data file name your are actually using?

4. When you substituted your filename, did you remove the @tempdir macro?

The script we have been playing with addresses only part of your goal and is for the most part only a concept. It does not include any code that would highlight the matching name. You must take it to the next step by replacing the entire message box section with your GUI mentioned at the head of this thread. For example, the global variable $aNames could be used to populate a list box in your GUI, and the $i variable in the While loop, of function _LookUpName, identifies the array indices containing the matched name.

@post #14:

also, I tried replacing the names in the au3 file with names in the program and it couldn't find it. I have a screenshot. http://www.crewxp.com/screenshot.jpg

I see it , but I don't believe it. Except, what is going on with the formatting of the Debug 3 message box on your end. A screen shot of how it should look is below (see attachment Debug3.jpg). On my end, the name is enclosed in quotes, and "not found in" is on the same line. Yours seems to have a line break before the closing quote. That indicates there is something strange going on, unless you have altered the script. Did you copy/paste AUBREY BRATCHER into the script, and possibly the string contains non-printing characters? Please post your "test.txt" data file created by the script.

Debug3.jpg

I added the names for AUBREY, Cody, Samantha, and David, and they worked just as well as Popeye (that is, no problems) (see attachment Debug2.jpg).

Debug2.jpg

ps, That's a good looking bunch of people, but I think the photographer needs glasses!


Phillip

Share this post


Link to post
Share on other sites

lol... that's funny. No, I photoshopped it for their faces to be blurred. For confidentiality reasons. It's 1:30 am, im tired. I'll get on this tomorow. Thx and cya

Share this post


Link to post
Share on other sites

Awesome, I got everything setup. Now I just have to get it to do what I want. I set it to the file that has all the names and it finds them! But, the point of the script is to eliminate the need of selecting every name then pressing ctrl + shift + F8 to index the name. Is there a way to have it select all the text in the text box, then find the name. If it finds it, then it highlights it, then pressing the ctrlshift f8 key, then finds the next name. After it's done, I move the mouse to another text box and it does it again. That'd be the ultimate goal. Thx alot.

Share this post


Link to post
Share on other sites

But, the point of the script is to eliminate the need of selecting every name then pressing ctrl + shift + F8 to index the name. Is there a way to have it select all the text in the text box, then find the name. If it finds it, then it highlights it, then pressing the ctrlshift f8 key, then finds the next name. After it's done, I move the mouse to another text box and it does it again. That'd be the ultimate goal. Thx alot.

I am 95% certain you can achieve your goals using AutoIt. From what I think you are saying in your post, the following pseudo code should do the trick when properly combined with the current script:

1. Triple clicking in the "text" box, using "MouseClick", should select all of the text, not just the word under the cursor as is currently being done (see the "clicks" parameter). I say "should" select all text because Triple clicking does not always do what it normally does (for example, it does not work in Notepad). If that's the case, perhaps using the "Send" function to press the "HOME" key may move the cursor to the start of the text, then another "Send" to hold the "SHIFT" key while sending the "END" key may select the entire line of text. You may have to experiment.

2. Using the "StringSplit" function, split the selected line of text into an array (with whatever character delimits each name).

3. Use a For Next loop to process each name in the array created by "StringSplit". The loop could process all names unattended, or each iteration could wait for a hot key to be pressed.

4. The array index number where the match occurs is the line number in the text File where the names reside. Use "Send("{HOME}") to position the cursor on the first line in the text file, then use "Send" again to move down that number of times. When the line is reached, use the "Send" key to hold down the SHIFT key and press the END key to highlight the entire line.

Something like that! Happy Autoit'ing, and keep me informed...


Phillip

Share this post


Link to post
Share on other sites

hey im back! sorry ive been out for so long. We've had problems with our server in the room. Phillips, do you have aim, msn, or a email? If so, that'd be awesome for us. I've come alittle farther on this, but not much. Been boggled down by work. Have you had any further progress on this issue? I tried, but havn't gotten far with those commands you gave me. We're not as intelectual as you. Thanks alot!

Share this post


Link to post
Share on other sites

hey im back! sorry ive been out for so long. We've had problems with our server in the room. Phillips, do you have aim, msn, or a email? If so, that'd be awesome for us. I've come alittle farther on this, but not much. Been boggled down by work. Have you had any further progress on this issue? I tried, but havn't gotten far with those commands you gave me. We're not as intelectual as you. Thanks alot!

<{POST_SNAPBACK}>

@CrewXP

I PM'd you. Log onto the forum and check you messages.


Phillip

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...