workingfast Posted August 7, 2018 Share Posted August 7, 2018 I've been programing in Autoit for a few years now. I've always been able to word my questions in searches and easily find answers. One reason I program in AutoIt is the community. For some reason I can't find the answer or word my issue poorly. Way back in the day in basic I could load a text file into an array. A Variable name with number like item$(1) Item$(2). This way I could continually pull a line from the array. I can load the text file into an array through Autoit and list the whole array. How do I pull a single line out as a variable? Say I have a list of 10 lines that contain PC names. I want to see what is stored in line 2. I can do this working from opening a file but don't want to keep reading the file from the disk. I hope I've explained this well and appreciate any help or point in the right direction. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 8, 2018 Moderators Share Posted August 8, 2018 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Malkey Posted August 8, 2018 Share Posted August 8, 2018 See FileReadToArray() function in the AutoIt help file and examine its example: and, See AutoIt Wiki - Accessing Data in Arrays. Be aware arrays in AutoIt are zero-based. So the first line of the file when using FileReadToArray(), has an index of zero when in the array. Link to comment Share on other sites More sharing options...
pixelsearch Posted August 8, 2018 Share Posted August 8, 2018 (edited) @workingfast : as your basic language knowledge tends to show it, you'd prefer line 1 in item$(1), line 2 in (2) etc... So there's another function, named _FileReadToArray, which allows you to do it (please note the underscore at the beginning of the function, compared to the FileReadToArray function explained by Malkey) Here is a simple script based upon _FileReadToArray, the text file to be read is... the script itself ! #include <File.au3> #include <MsgBoxConstants.au3> Local $aArray _FileReadToArray(@ScriptFullPath, $aArray) _ArrayDisplay($aArray,"File content : " & $aArray[0] & " lines", "1:", 0, Default, "Line content") Msgbox($MB_SYSTEMMODAL, "Line 2 in Index 2", "Line 2 = " & $aArray[2]) 7 lines in this script, here are the results when you run it : You can use this script directly after replacing @ScriptFullPath with your text file name, then access line x with $aArray[x] And if you want to know how many lines contains your text file, the answer is in $aArray[0]... or in Malkey's Ubound($aArray) - 1 Just choose the method you prefer and good luck Edited August 11, 2018 by pixelsearch 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