DitoMuertez Posted March 26, 2011 Share Posted March 26, 2011 So, I only first heard of AutoIt about 4 days ago, which is amazing because it seems like a very powerful language. But anyway, I'm writing a script that works in conjunction with a c# program. The c# program checks to see if certain programs are installed, and if not downloads them and creates a temp text file. C# then hands off processing to the AutoIt script to read the text file and install the newly downloaded files. Here's a sample of what file.txt looks like program1.exe program2.exe I'm pretty sure that since I don't really know what I'm doing with AutoIt, I'm not using it with the most efficiency, but for now I just want it to work, it was difficult for me to narrow this down, but it looks like where I'm trying to assign values to the different indexes of the array, nothing is being assigned. Can anyone help, or at least point me in the right direction? Script below: #include <Array.au3> #include <file.au3> #RequireAdmin FileChangeDir(@AppDataCommonDir & "\myProgram\Temp\") If FileExists ("file.txt") <>1 Then MsgBox(0, "Error", "Text File Not Found") Exit EndIf Const $file = FileOpen ("file.txt",0) Local $c = 0, $line If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $c = $c + 1 WEnd Local $array[$c] $c = 0 ;I believe this while loop is where it breaks ;the second line was only put there to test and see what is in the current variable/array ;It looks like $line is not being assigned anything in the first line While 1 $line = FileReadLine($file) MsgBox(0, "Test", string($line)) If @error = -1 Then ExitLoop $array[$c] = $line $c = $c + 1 WEnd FileClose ($file) $c = 0 ;this line, again, is only to let me know if the script made it here without error local $msgTest = String ($toBeInstalled[$c]) MsgBox (0, "test", $msgTest) While 1 RunWait ($array[$c]) If @error = -1 Then ExitLoop $c = $c + 1 WEnd ;this line, again, is only to let me know if the script made it here without error MsgBox(0,"Fin","Code Completed successfully") Exit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 26, 2011 Moderators Share Posted March 26, 2011 DitoMuertez,Welcome to the AutoIt forum. You are making rather a meal of all that - it can be done in 3 lines: ; Include the UDF #include <File.au3> ; Declare the array Local $aArray ; Read the file into the array _FileReadToArray(@AppDataCommonDir & "\myProgram\Temp\file.txt", $aArray)And Robert is your mother's brother! Of interest the problem in your original script was that you were running 2 successive loops using FileReadLine. Each time you call FileReadLine with no parameter AutoIt augments the count by 1 which meant that the second loop started reading past the end of the file - thus you never read anything. You needed to reset the count for the second loop. Furthermore you did not really need the first loop anyway - there is a nice little function called _FileCountLines which does that job. But all that is moot as the snippet above shows you how to do it in the easiest way! Please ask if anything is unclear. M23P.S. If you post code in the future, please use code tags - put [autoit] before and [/autoit] after the code. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
DitoMuertez Posted March 26, 2011 Author Share Posted March 26, 2011 Thank you Sir! makes perfect sense, i knew i was making it more complicated than it had to be. And the funny thing is, I remember reading somewhere that filereadline() goes concurrently to the next line...hell, I was even using it that way. . But yeah, thanks again. Also, about the tags, I knew I was missing something, will use next time. Link to comment Share on other sites More sharing options...
DitoMuertez Posted March 26, 2011 Author Share Posted March 26, 2011 A note to add: Originally, I was using filereadtoarray, but i wasn't sure if it was going to separate the indexes by line or not. At that time, I wasn't sure how to display the contents of the array, which was why I counted and built the way I did. 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