Jump to content

Read A File To An Array HELP


 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

_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
Link to comment
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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...