leonardator Posted June 22, 2011 Share Posted June 22, 2011 I'm trying to use autoit to read a line of text that has been split up by commas. I then want it to use each set of characters between the commas to fill out some billing procedures. I was thinking something kind of like this: For example, if i have the sentence "The,number,you,are,looking,for,isn't,here" in a text file, I assume this function would split the string up, and put each word in an array $arr[0] to $arr[8]. $file = FileOpen("text.txt") FileLineRead("$file", 1) $arr[8] $arr = Stringsplit("$file" ",") After that, I want to activate the billing program, and put the characters from the array in as values, and press enter after doing that. Winactivate(billing program) ConsoleWrite($arr[1]) Send("{ENTER}") Sleep(500) ConsoleWrite($arr[2]) Send("{ENTER}") And so on and so on. Then I want it to read the second line of the file, and do the same thing over again. This is my first project, so some help would be appreciated. Link to comment Share on other sites More sharing options...
sleepydvdr Posted June 22, 2011 Share Posted June 22, 2011 I think this would do it: #include <file.au3> #include <array.au3> for $i = 1 to 10 ; Loops 10 times. Change it to loop as many times as you wish. $file = FileReadLine("text.txt", $i) $arr1 = Stringsplit($file, ",") Winactivate(billing program) ConsoleWrite($arr[1]) Send("{ENTER}") Sleep(500) ConsoleWrite($arr[2]) Send("{ENTER}") Next Just to note, you put quotes around your variable. If you put quotes around it, it becomes a string, not a variable. #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
hannes08 Posted June 22, 2011 Share Posted June 22, 2011 Hi leonardator, I would rather use _FileReadToArray() or using FileReadLine() in a WHILE loop than using FOR with a fixed loop count. What happens if your textfile is empty? Your script will crash then. Also please note that ConsoleWrite() will NOT send anything to an application. Use Send or ControlSend() Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
leonardator Posted June 22, 2011 Author Share Posted June 22, 2011 Ok, I thought ConsoleWrite() would just put text in the top window. If i use _filetoarray would I be able to do individual lines as an array? Link to comment Share on other sites More sharing options...
hannes08 Posted June 22, 2011 Share Posted June 22, 2011 If you look up _FileReadToArray() In the help file you'll see that as a result you have an array like this: $array[0] = 5 ;~ Amount of lines read from file $array[1] = "This is the first line of text" $array[2] = "2nd line" $array[3] = "3rd" $array[4] = "4th" $array[5] = "last line" Then you can easily address each line: For $i = 1 To $array[0] ;Here you can do sth with $array[$i] as this is the actual line. Next Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
leonardator Posted June 22, 2011 Author Share Posted June 22, 2011 Ok, I don't think I was quite clear as to what I need. I need to have the information in each line be read at a time, and I need to be able to use information between the commas individually. If i had the line of text that looked like this: the,number,that,you,are,looking,for,is,here,somewhere I need to be able to send individual words, or in the actual program, sets of numbers and letters, to my billing program. But the real kicker is this, after it's done with the first line of text, the rest of the lines won't have as many sets of data between the commas. Or should I just generate my text file as data points like this: the number that you are looking You get the point. Link to comment Share on other sites More sharing options...
iamtheky Posted June 22, 2011 Share Posted June 22, 2011 Dont exactly understand the endgame, but hopefully this moves you along a bit. #Include <File.au3> $max = _FileCountLines ("C:\test.txt") $file = FileOpen("C:\test.txt" , 0) for $p = 1 to $max $line = FileReadLine($file , $p) _splitTOconsole ($line) next FileClose ($file) Func _splitTOconsole ($string) $sarray = stringsplit ($string , "," , 2) for $i = 0 to ubound($sarray) - 1 consolewrite($sarray[$i] & @CRLF) If $i = ubound($sarray) - 1 Then consolewrite ("-------end of line-------" & @CRLF) next EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now