snowman533 Posted April 20, 2009 Share Posted April 20, 2009 (edited) hey guys, ive almost got arrays figured out i want to get all the lines from a txt file that actually have text and display them in a MsgBox i have no trouble getting the first line to show how do i show/get the rest? #Include <Array.au3> #Include <File.au3> Dim $aArray[4] Dim $sDelim dim $i $fpath=@desktopdir & "\read to array.txt" _FileReadToArray($fpath, $aArray) _ArrayToString($aArray, @TAB, 1, 4) msgbox(0, "results", $aArray[1]) most of this was acquired from the help file, however i cannot help noticing i am still missing something, tried search and found nothing cannot find an example that suits my needs also, how do i get the script to automatically resize the array according to how many lines in the txt file, say if i update the file with a few lines? thanks in advance *edit* attached is the txt file i am working off, currently it is being used as a test, once this is sorted out ill be using it for something else *edit2* fixed some spellingread_to_array.txt Edited April 20, 2009 by snowman533 Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
Juvigy Posted April 20, 2009 Share Posted April 20, 2009 Actually this works great - you just are displaying only one part of the array. Try this : msgbox(0, "results", $aArray[0]) msgbox(0, "results", $aArray[1]) msgbox(0, "results", $aArray[2]) msgbox(0, "results", $aArray[3]) msgbox(0, "results", $aArray[4]) Link to comment Share on other sites More sharing options...
snowman533 Posted April 20, 2009 Author Share Posted April 20, 2009 say if i add another few lines to my file, how do i automatically add them? do i have to go in and change the number? i want to release a certain program that works of a text file but i do not want to change the program every time i update the text file is there a way to do this Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
jinxter Posted April 20, 2009 Share Posted April 20, 2009 _ArrayDisplay($aArray) will list the values in the array. ReDim will help you ReDim the Array if needed. The _Array commands will help you aswell. It's all in the helpfile how to use these commands. > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
99ojo Posted April 20, 2009 Share Posted April 20, 2009 (edited) say if i add another few lines to my file, how do i automatically add them? do i have to go in and change the number? i want to release a certain program that works of a text file but i do not want to change the program every time i update the text file is there a way to do thisHi, try this: #Include <Array.au3> #Include <File.au3> Dim $aArray Dim $sDelim dim $i $fpath=@desktopdir & "\read to array.txt" _FileReadToArray($fpath, $aArray) _Arraydisplay ($aArray) Edited April 20, 2009 by 99ojo Link to comment Share on other sites More sharing options...
snowman533 Posted April 20, 2009 Author Share Posted April 20, 2009 thankyou 99ojo #Include <Array.au3> #Include <File.au3> Dim $aArray[4] Dim $sDelim dim $i $fpath=@desktopdir & "\read to array.txt" _FileReadToArray($fpath, $aArray) For $i = 1 to UBound ($aArray) - 1 msgbox(0, "results", $aArray[$i]) Next worked, now to add it to my program, thanks again Intermediate AutoIt/Autohotkey User Link to comment Share on other sites More sharing options...
99ojo Posted April 20, 2009 Share Posted April 20, 2009 thankyou 99ojo #Include <Array.au3> #Include <File.au3> Dim $aArray[4] Dim $sDelim dim $i $fpath=@desktopdir & "\read to array.txt" _FileReadToArray($fpath, $aArray) For $i = 1 to UBound ($aArray) - 1 msgbox(0, "results", $aArray[$i]) Next worked, now to add it to my program, thanks again No problem, i changed the code. Just delete [4] at Line Dim $aArray [4]. You don't have to Dim your array exactly beforehand, if you use _FileReadToArray. ;-)) Stefan Link to comment Share on other sites More sharing options...
snowman533 Posted April 20, 2009 Author Share Posted April 20, 2009 (edited) heres the full code made a few adjustments thanks again, works perfect now to figure out a way to give u credit in my prog #Include <Array.au3> #Include <File.au3> if FileExists(@scriptdir & "\KILLED.txt") Then FileDelete(@scriptdir & "\KILLED.txt") EndIf Dim $aArray $fpath=@scriptdir & "\Baddies.txt" _FileReadToArray($fpath, $aArray) Dim $sProcesses = _ArrayToString($aArray) Dim $aProcesses = StringSplit($sProcesses, '|') Dim $aProcList = ProcessList() dim $hLog = FileOpen("KILLED.txt",9) $ProcessesKilled = 0 For $i = 1 To $aProcesses[0] IF ProcessExists($aProcesses[$i]) THEN WHILE ProcessExists($aProcesses[$i]) ProcessClose($aProcesses[$i]) FileWriteLine($hLog, $aProcesses[$i]) $Processeskilled += 1 WEND ENDIF Next MsgBox(0,"Results", $ProcessesKilled & " bad programs found, please see: 'KILLED.txt' and 'Process Definitions.txt' in this programs directory" & @lf & @lf & "Current program directory: " & @scriptdir) FileClose($hLog) solved *edit* btw the top If is to make sure that the log is not currently existing, if it is it deletes it, else it will continue from the bottom of the previous scan Edited April 20, 2009 by snowman533 Intermediate AutoIt/Autohotkey User 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