peter1234 Posted February 26, 2006 Share Posted February 26, 2006 (edited) I hope this will be of help to someone. Shows how to make array, save array to file, read array from file. expandcollapse popup;**** array tutorial by peter1234 **** ;requires beta AutoIt #include <GuiConstants.au3> #include <Array.au3> #include <file.au3> ;************ ;make array ;************ Dim $MyArray[1] For $n = 101 to 105 _ArrayAdd($MyArray, $n/10 ) Next $MyArray[0] = Ubound($MyArray) - 1 _ArrayDisplay($MyArray, "array") ;************************ ;save array to text file ;************************ FileChangeDir (@scriptdir ) FileDelete ("array.txt") FileOpen("array.txt",1) For $x = 0 to $MyArray[0] FileWrite("array.txt", $MyArray[$x] ) If $x<>$MyArray[0] then FileWrite("array.txt", @CRLF ) Next FileClose("array.txt") MsgBox(0, "", "array written to text file ") ;************************** ;read array from text file ;************************** FileChangeDir (@scriptdir ) If FileExists ("array.txt")<>1 then MsgBox(0, "ERROR", "Array text file not found ") Exit EndIf Dim $NewArray FileOpen("array.txt",0) If Not _FileReadToArray("array.txt",$NewArray) Then MsgBox(4096,"Error", " Error reading text file to $NewArray error:" & @error) EndIf FileClose("array.txt") ;************************* ;display NewArray as read ;************************* _ArrayDisplay($NewArray, "as read") ;************************ ;display fixed NewArray ;************************ _ArrayDelete ( $NewArray, 0 ) _ArrayDisplay($NewArray, "fixed") Exit Simplified with suggestion by CHRIS95219 ;**** array tutorial by peter1234 (simplified) **** ;requires beta AutoIt #include <GuiConstants.au3> #include <Array.au3> #include <file.au3> ;************ ;make array ;************ Dim $MyArray[1] For $n = 101 to 105 _ArrayAdd($MyArray, $n/10 ) Next $MyArray[0] = Ubound($MyArray) - 1 ;*********************** ;display original array ;*********************** _ArrayDisplay($MyArray, "array") ;************************ ;save array to text file ;************************ _FileWriteFromArray("array.txt" , $MyArray,1) MsgBox(0, "", "array was written to text file ") ;************************** ;read array from text file ;************************** Dim $NewArray If Not _FileReadToArray("array.txt",$NewArray) Then MsgBox(4096,"Error", " Error reading Array error:" & @error) Exit EndIf ;********************************** ;display array read from text file ;********************************** _ArrayDisplay($NewArray, "as read") Edited February 26, 2006 by peter1234 GoogleGonnaSaveUs 1 Link to comment Share on other sites More sharing options...
GaryFrost Posted February 26, 2006 Share Posted February 26, 2006 (edited) How about showing how it's done with out UDFs i.e. Example 1: Dim $MyArray[1] For $n = 1 to 5 ReDim $MyArray[UBound($MyArray) + 1]; preserves the values in the array instead of removing the values while resizing an array Next $MyArray[0] = Ubound($MyArray) - 1; use index zero as size holder MsgBox(0,"Array", "Size: " & $MyArray[0] & ", excluding zero index in this case used for size of array") Example 2: Dim $MyArray[1] For $n = 0 to 3 ReDim $MyArray[UBound($MyArray) + 1]; preserves the values in the array instead of removing the values while resizing an array Next MsgBox(0,"Array", "Size: " & UBound($MyArray) ) Edited February 26, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Skizmata Posted July 23, 2007 Share Posted July 23, 2007 I have been really wanting to be able to make this work give me a hand with the code I can't make it work! #include <Array.au3> Dim $MyArray _ArrayAdd($MyArray,"Number Ten") _ArrayAdd($MyArray,"Number Nine") _ArrayAdd($MyArray,"Number Eight") _ArrayAdd($MyArray,"Number Seven") _ArrayAdd($MyArray,"Number Six") _ArrayAdd($MyArray,"Number Five") _ArrayAdd($MyArray,"Number Four") _ArrayAdd($MyArray,"Number Three") _ArrayAdd($MyArray,"Number Two") _ArrayAdd($MyArray,"Number One") For $n = 1 to 5 ReDim $MyArray[UBound($MyArray) + 1]; preserves the values in the array instead of removing the values while resizing an array Next $MyArray[0] = Ubound($MyArray) - 1; use index zero as size holder MsgBox(0,"Array", "Size: " & $MyArray[0] & ", excluding zero index in this case used for size of array") AutoIt changed my life. Link to comment Share on other sites More sharing options...
randallc Posted July 23, 2007 Share Posted July 23, 2007 (edited) Hi, if someone hasn't done it yet; ; arraytute.au3 #include <Array.au3> $MyArray=_ArrayCreate("") ;~ Dim $MyArray _ArrayAdd($MyArray,"Number Ten") _ArrayAdd($MyArray,"Number Nine") _ArrayAdd($MyArray,"Number Eight") _ArrayAdd($MyArray,"Number Seven") _ArrayAdd($MyArray,"Number Six") _ArrayAdd($MyArray,"Number Five") _ArrayAdd($MyArray,"Number Four") _ArrayAdd($MyArray,"Number Three") _ArrayAdd($MyArray,"Number Two") _ArrayAdd($MyArray,"Number One") ;~ For $n = 1 to 5 ;~ ReDim $MyArray[UBound($MyArray) + 1]; preserves the values in the array instead of removing the values while resizing an array ;~ Next $MyArray[0] = Ubound($MyArray) - 1; use index zero as size holder _ArrayDisplay($MyArray) MsgBox(0,"Array", "Size: " & $MyArray[0] & ", excluding zero index in this case used for size of array")Best, randall; better to follow; Edited July 23, 2007 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
randallc Posted July 23, 2007 Share Posted July 23, 2007 (edited) #include <Array.au3> local $MyArray[10]=["Number One","Number Two","Number Three","Number Four","Number Five","Number Six","Number Seven","Number Eight","Number Nine","Number Ten"] _ArrayDisplay($MyArray) Edited July 23, 2007 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW 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