Jump to content

Read file into 2D Array


Recommended Posts

Hi

I'm trying to create a 2D Array with a file that is TAB delimited but can't figure out how.

File Content:

abcd    <tab>  1234

asdf   <tab>  dfsa

aetg    <tab> adfa

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Check()

Func Check()
    Local $ArraryList
    Local $File = @ScriptDir & "\LocalAdminRem12072017.txt"
    Local $Array = _FileReadToArray($File, $ArraryList, "", @TAB)
    _ArrayDisplay($Array)
EndFunc

 

Link to comment
Share on other sites

2 minutes ago, SlackerAl said:
#include <Array.au3>
#include <File.au3>

Check()

Func Check()
    Local $ArraryList
    Local $Array = _FileReadToArray("test.txt", $ArraryList, 4, @TAB)
    _ArrayDisplay($ArraryList, "2D display")
EndFunc

 

I've also tried that and the script just runs then closes without any errors:

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Check()

Func Check()
    Local $ArraryList[1]
    Local $File = @ScriptDir & "\LocalAdminRem12072017.txt"
    Local $Array = _FileReadToArray($File, $ArraryList, 4, @TAB)
    _ArrayDisplay($Array, "Arrary")
EndFunc

SciTE output:

>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\usa\Documents\Altiris\RemAdmin\RemAdminRem.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>10:47:02 AutoIt3.exe ended.rc:0
+>10:47:02 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.966

Edited by antmar904
Link to comment
Share on other sites

Oops, I see what I did wrong I was calling the wrong variable.  This is working now:

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Check()

Func Check()
    Local $ArraryList
    Local $File = @ScriptDir & "\LocalAdminRem12072017.txt"
    MsgBox(0, "", $File)
    Local $Array = _FileReadToArray($File, $ArraryList, 4, @TAB)
    _ArrayDisplay($ArraryList, "Arrary")
EndFunc

 

Edited by antmar904
Link to comment
Share on other sites

How do I display only column one or only column two in the array?

How would I specify the different columns in a 2D array?

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Check()

Func Check()
    Local $ArrayList[2]
    Local $File = @ScriptDir & "\LocalAdminRem12072017.txt"
    ;MsgBox(0, "", $File);debug
    Local $Array = _FileReadToArray($File, $ArrayList, 4, @TAB)
    _ArrayDisplay($ArrayList, "Arrary")

    For $i = 0 To $ArrayList - 1
        MsgBox(0, "", $ArrayList[$i]);show each row in the first column of the array.
    Next
EndFunc

 

Edited by antmar904
Link to comment
Share on other sites

4 minutes ago, antmar904 said:

How do I display only column one or only column two in the array?

How would I specify the different columns in a 2D array?

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Check()

Func Check()
    Local $ArrayList[2]
    Local $File = @ScriptDir & "\LocalAdminRem12072017.txt"
    ;MsgBox(0, "", $File);debug
    Local $Array = _FileReadToArray($File, $ArrayList, 4, @TAB)
    _ArrayDisplay($ArrayList, "Arrary")

    For $i = 0 To $ArrayList - 1
        MsgBox(0, "", $ArrayList[$i]);show each row in the first column of the array.
    Next
EndFunc

 

I figured it out :)

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Check()

Func Check()
    Local $ArrayList
    Local $File = @ScriptDir & "\LocalAdminRem12072017.txt"
    ;MsgBox(0, "", $File);debug
    Local $Array = _FileReadToArray($File, $ArrayList, 4, @TAB)
    _ArrayDisplay($ArrayList, "Array")

    For $i = 0 To UBound($ArrayList) - 1
        MsgBox(0, "", $ArrayList[$i][0]);show each row in the first column of the array
    Next
EndFunc

 

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...