Sym98 Posted May 25, 2011 Share Posted May 25, 2011 (edited) Hello everyone, I need to know how to get the same result as of the underlying code, in case the contents of the txt file was stored in a variable. #include <File.au3> Dim $aArray _FileReadToArray("File.txt",$aArray) MsgBox(0,"Text",$aArray[1]) MsgBox(0,"Text",$aArray[2]) MsgBox(0,"Text",$aArray[3]) Thank you in advance Edited May 25, 2011 by Sym98 Link to comment Share on other sites More sharing options...
bogQ Posted May 25, 2011 Share Posted May 25, 2011 (edited) you need some other example to populatie array if i understand you correctly?! #Include <Array.au3> Dim $arr[20] $arr[0] = UBound($arr)-1 _ArrayDisplay($arr) For $x = 1 To $arr[0] $arr[$x] = @SEC&":"&@MSEC Sleep(10) Next _ArrayDisplay($arr) if not so, pls be more specific Edited May 25, 2011 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 25, 2011 Moderators Share Posted May 25, 2011 Sym98,This gives you the same array as if you read the string in from a file with _FileListToArray: #include <Array.au3> $sString = "Line 1" & @CRLF & "Line 2" & @CRLF & "Line 3" $aArray = StringSplit($sString, @CRLF, 1) _ArrayDisplay($aArray)M23 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...
GEOSoft Posted May 25, 2011 Share Posted May 25, 2011 (edited) First off, you should not be using Dim to declare an empty array. Use Global, Local or Static and you will get the same result. Local $sTest = "This is some" & @CRLF & @CRLF & "test string" ;;Global $Array _StringReadToArray($sTest, $Array);; Method 1 ;; _StringReadToArray(FileRead("C:\Somefile.txt"), $Array);; Method 2 ;; _StringReadToArray("C:\Somefile.txt", $Array);; Method 3 Func _StringReadToArray($s_String, ByRef $a_Array) If FileExists($s_String) Then $s_String = FileRead($s_String) If NOT $s_String Then Return SetError(1, 1, "There is no valid string to parse") Local $a_Result = StringRegExp($s_String, "(?m:^).*", 3) If NOT @Error Then $a_Array = $a_Result Return $a_Array EndIf Return SetError(1, 2, "Unable to create the new array") EndFunc You can pass the function either a string or a file name. If you pass it the file name there is no need for _FileReadToArray(). See the 3 methods that are useable. Edited May 25, 2011 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Sym98 Posted May 25, 2011 Author Share Posted May 25, 2011 (edited) Thank you all, as soon as I get time I'll try the codes you gave me Edited May 25, 2011 by Sym98 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