Sign in to follow this  
Followers 0
SteveO

Read A File To An Array HELP

6 posts in this topic

#1 ·  Posted (edited)

I'm trying to read a file to an array, then outputting the line into a message box. I know it's probably a simple thing that I'm just not seeing....

Dim $aMessages
    $file = FileOpen("messages.txt", 0)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
        _FileReadToArray("messages.txt", $aMessages)
        MsgBox(0, "Test" & $ver, $aMessages)
    FileClose($file)
Edited by SteveO

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm trying to read a file to an array, then outputting the line into a message box. I know it's probably a simple thing that I'm just not seeing....

Dim $aMessages
    $file = FileOpen("messages.txt", 0)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
        _FileReadToArray("messages.txt", $aMessages)
        MsgBox(0, "Test" & $ver, $aMessages)
    FileClose($file)
_FileOpen() ... Remove that... _FileReadToArray() already has it in it.

Edit:

Also, once it is done, $aMessages will be an array, you can't check it like MsgBox(0, 0, $aMessage)

It will have elements ie... $aMessage[0] will equal something, $aMessage[1] will equal something etc...

Use _ArrayDisplay($aMessages, "my array") to see the result.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

_FileOpen() ... Remove that... _FileReadToArray() already has it in it.

Edit:

Also, once it is done, $aMessages will be an array, you can't check it like MsgBox(0, 0, $aMessage)

It will have elements ie... $aMessage[0] will equal something, $aMessage[1] will equal something etc...

Use _ArrayDisplay($aMessages, "my array") to see the result.

Okay, changed the code too...

Dim $aMessages
        _FileReadToArray("messages.txt", $aMessages)
        MsgBox(0, "Test" & $ver, $aMessages)

Still doesn't wana output the array.

EDIT:

Okay, cool it works! Thanks =)

Edited by SteveO

Share this post


Link to post
Share on other sites

You need to use _ArrayDisplay for that:

#include <file.au3>
#include <array.au3>
Dim $as_MessageTxt
_FileReadToArray("messages.txt",$as_MessageTxt)
_ArrayDisplay($as_MessageTxt)

You should now be able to see the array.

- The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

You need to use _ArrayDisplay for that:

#include <file.au3>
#include <array.au3>
Dim $as_MessageTxt
_FileReadToArray("messages.txt",$as_MessageTxt)
_ArrayDisplay($as_MessageTxt)

You should now be able to see the array.

- The Kandie Man ;-)

That's actually EXACTLY what i was looking for. THANKS!!! =)

Share this post


Link to post
Share on other sites

You need to use _ArrayDisplay for that:

#include <file.au3>
#include <array.au3>
Dim $as_MessageTxt
_FileReadToArray("messages.txt",$as_MessageTxt)
_ArrayDisplay($as_MessageTxt)

You should now be able to see the array.

- The Kandie Man ;-)

:)http://www.autoitscript.com/forum/index.ph...st&p=388376

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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