Sign in to follow this  
Followers 0
Sym98

[Help] Replace _FileReadToArray

5 posts in this topic

#1 ·  Posted (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 :huh2:

Edited by Sym98

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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.

 

Share this post


Link to post
Share on other sites

Sym98,

This gives you the same array as if you read the string in from a file with _FileListToArray: :huh2:

#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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 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!"

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank you all, as soon as I get time I'll try the codes you gave me :huh2:

Edited by Sym98

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0