Sign in to follow this  
Followers 0
shornw

using an Array

9 posts in this topic

Hi all

is it possible to read a comma seperated file to an array so that each item becomes a seperate array column. I have a .txt file which is written when users logon to the domain, below is a typical line:

SmithF, PC1234, Fred Smith, Finance, 1234

JonesB, PC3456, Bill Jones, Sales, 7890

What I want to do is read this line into an array so that each item is read into a seperate column. If I use _FileReadToArray every item on each line is written into one single column.

Sorry if this is obvious

Thanks for looking


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites



shornw,

Do it in 2 steps within an outer loop: :blink:

- 1. Use StringSplit to get the next single line into a 1D array.

- 2. Use an inner loop to read the elements from that 1D array into the correct elements of the final 2D array.

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

#3 ·  Posted (edited)

#include <Array.au3> ;just to show array

$sString = "SmithF, PC1234, Fred Smith, Finance, 1234"

$atemp = StringSplit($sString,",",2)

Local $aArray[1][UBound($atemp)]
For $i = 0 to UBound($atemp) -1
    $aArray[0][$i] = $atemp[$i]
Next
$atemp = 0

_ArrayDisplay($aArray)
I'm in a jovial mood today.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I was curious , so ..

include <Array.au3> ;just to show array

$sString = "SmithF, PC1234, Fred Smith, Finance, 1234,Test2, PC1235, Test 2, Germany, 1235"
$atemp = StringSplit($sString,",",2)
Local $aArray[1][5]
$i=0
$b=0
Do
    For $j = 0 to 4
        $aArray[$b][$j] = $atemp[$i]
        $i=$i+1
    Next
    ReDim $aArray[UBound($aArray)+1][5]
    $b=$b+1
Until $i>UBound($atemp)-1
_ArrayDisplay($aArray,$i)

Share this post


Link to post
Share on other sites

Thanks for your replies, very helpful.

I hit a wall in another pway now. My thinking went this way:

$sString = "SmithF, PC1234, Fred Smith, Finance, 1234"

$split = StringSplit($sString, ",")

If $split[1] = @UserName And $split[2] = @ComputerName Then Exit

Can anyone tell me why, although $split[1] returns the username and $split[2] returns the PC name the If/Then will not work.

Thanks again


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

Mat...... can you come and shoot me. That much stupidity doesn't deserve to live!!!

Thank you, this is the last bit of a huge data collection script which needs to be completed by Friday...and I have to leave at 12 tomorrow.

REALLY much appreciated.

I love this forum


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

Mat...... can you come and shoot me. That much stupidity doesn't deserve to live!!!

:blink:

You'll only really find bugs like that when you know what you're looking for to start with. The good news is that you won't make that mistake again, so you can only be shot once ;)

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