Think of something that you wish Authorware could do but it doesn't?  Let the our good friends at Macromedia know via the wishlist.

Please let us know if you find any of the materials on this site inappropriate or offensive. Please include the url and why the material should be reviewed.

Comments and questions about the site are also welcome. Please no Authorware questions, use the AWARE list.


B5013 - How do I search through several files for a target string?

by - Joseph Ganci

Is there a limit to the number of lines the Authorware will search through when using the GetLine function?

I have a file with 200 lines to search through it works fine. This was the sample I have been working with. Today the "real sample" came in from client with 23,581 lines. I ran my code and it will search through 600 lines and stop. The total file has approximately 1,155,400 characters. Have I just been blindsided by a limit?

A character string can be at most 30000 characters. I suspect that is the limit you're hitting with 600 lines, and not that there is a limit to the number of lines themselves, for all practical purposes.

What you'll need to do, unfortunately, is to split up that large file in many files, 30000 characters or less. You'll then have to search through each one to find the target. If you wish to make them cumulative, you'll need to add the number of lines of each file as you search.

First, I created 3 text files and called them test01.txt, test02.txt, and test03.txt. I then wrote the following script:

1. files := Catalog(FileLocation, "f")
2. target := "Joe"
3. line count := 0
4. repeat with i := 1 to 99
5. text := ReadExtFile(FileLocation ^ "test" ^ Test(i < 10, "0", "") ^ i ^ ".txt")
6. if text = "" then exit repeat
7. found line num := LineCount(SubStr(text, 1, Find(target, text)))
8. if found line num > 0 then exit repeat
9. line count := line count + LineCount(text)
10. end repeat
11. if found line num > 0 then found line num := found line num + line count

Of course the line numbers aren't in the script, I added them above to help explain the script here.

Line 1 reads in a copy of all the files in the current location. If your text files are in another folder, you'll need to change the location here.

Line 2 sets up the target to search, in this case yours truly.

Line 3 resets the line count to 0 in case we've run this before during the current session.

Line 4 sets up a repeat loop to search through up to 99 files (test01.txt - test99.txt)

Line 5 reads in the next available text file, according to the current loop iteration (i).

Line 6 checks if the text file came back empty, which means we've run out of the files and should exit the repeat loop.

Line 7 checks the current text file's contents. If the target is found the variable "found line num" will contain the line number, if not it will be set to 0.

Line 8 checks to see if the number is not 0, which means it was found, and the repeat loop is exited.

Line 9 will run if the target was not found and it will add the number of lines in the current file to the however many lines were in previous files searched.

Line 10 will repeat the loop, assuming we haven't exited in line 6 or line 8 or we haven't checked 99 files.

Line 11 will add the line number in which the target was found in the last file searched to however many lines were in previous files, giving us a total line number as if all the files were in one big text file. If the target was not found, then the "found line num" variable will remain as 0.

One thing to keep in mind to obtain the correct results is to make sure your text files don't have extraneous blank lines at the end: there should be none.

There are 0 reviews
Add your review