Page 1 of 1 1
Topic Options
#137738 - 2005-04-12 02:16 PM Split Array
Testprs Offline
Fresh Scripter

Registered: 2004-09-02
Posts: 20
Loc: Netherlands, Delft
Hi,

I'm trying to create a script that reads from a csv file. I then want the text from each column to be split in two. this is the code I've created so far (maybe this explains a bit more)

Code:
 
IF Open(3,"C:\helpdesk\kix\la.csv") = 0
$x = ReadLine(3)
WHILE @ERROR = 0
$Value = Split($x,",")
For Each $Element In $Value
? $Element
Next
$x = ReadLine(3)
LOOP
Close (3)
ELSE
BEEP
? "Cannot open file, error code: [" + @ERROR + "] + " " "@SERROR""
ENDIF



The la.csv file exists of two columns with value's that belong together. How can I split these values? example:
$ElementPart1 $ElementPart2

regards,

Jeroen

Top
#137739 - 2005-04-12 02:33 PM Re: Split Array
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I think its best if you show us a couple of lines from your csv file. What delimits the fields between commas ? Get the impression your csv file looks like:

item1 item2, item 3 item4
item1 item2, item 3 item4
...


-Shawn

Top
#137740 - 2005-04-12 02:46 PM Re: Split Array
Testprs Offline
Fresh Scripter

Registered: 2004-09-02
Posts: 20
Loc: Netherlands, Delft
csv file:
computer1,user1
computer2,user2
computer3,user3

it's for usage in another script. this other script checks pc's for local admin rights and removes them unless they are in a list. This list is currently a big script, but by providing a csv file there will be a better view on who has these rights.

regards,

jeroen

Top
#137741 - 2005-04-12 02:49 PM Re: Split Array
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Think you got all code there, and working:

Code:

break on

IF Open(3,".\t.csv") = 0
$x = ReadLine(3)
WHILE @ERROR = 0
$Value = Split($x,",")
If UBound($Value) > 0
$computer = $Value[0]
$user = $Value[1]
?"computer=" + $computer + " user=" + $user
Endif
$x = ReadLine(3)
LOOP
$= Close (3)
ELSE
BEEP
? "Cannot open file, error code: [" + @ERROR + "] + " " "@SERROR""
ENDIF



-Shawn

Top
#137742 - 2005-04-12 02:52 PM Re: Split Array
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
you can also use ReadFile() to import the file into an array

then do a for each, split each element, ...
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137743 - 2005-04-12 03:04 PM Re: Split Array
Testprs Offline
Fresh Scripter

Registered: 2004-09-02
Posts: 20
Loc: Netherlands, Delft
Thanks... works like a charm!
could you please give me some more info on what the code exactly does?
what does UBound do? I looked it up in the manual, but couldn't really figure it out (total newby! )
what do the [number] value's mean in $Value[0] and $Value[1]?

thanks for the help...
regards,

jeroen

Top
#137744 - 2005-04-12 03:19 PM Re: Split Array
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
ubound = number of elements in an array
[number] = the item in an array (starting at 0)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 837 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.056 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org