normandbr
(Fresh Scripter)
2005-04-29 04:24 AM
Coma delimited files

Is there a way to read comma delimited files and put each segment in a variable. I know how to do it with a space delimited but with a coma delimited ???

Les
(KiX Master)
2005-04-29 05:04 AM
Re: Coma delimited files

It is done exactly the same except you Split() on the comma. Show us your code and a sample of the file.

normandbr
(Fresh Scripter)
2005-04-29 06:04 PM
Re: Coma delimited files

Let's say the array is $ar and come from a text files and I want to split each segment in a different variable. I did try this and it does not work.

redirectoutput ('log.txt')
$Ar = 1,2,3,5,7,11,17,13
$x = ASCAN($Ar, 13) ; will return '7'

? $x

sleep 5
$a = SPLIT ('$Ar', ',', 1)
;$b= SPLIT ("$array", ",", 1)
;$c= SPLIT ("$array", ",", 2)
;$d= SPLIT ("$array", ",", 3)
;$e= SPLIT ("$array", ",", 4)
;$f= SPLIT ("$array", ",", 5)
;$g= SPLIT ("$array", ",", 6)
;$h= SPLIT ("$array", ",", 7)



? $a
;? $b
;? $c
;? $d
;? $e
;? $f
;? $g
;? $h
sleep 15


Les
(KiX Master)
2005-04-29 06:13 PM
Re: Coma delimited files

First off, $AR is an array of values, not a comma delimited string.
Code:
break on
$CommaDelimString = '1,2,3,4,5,6,7,8,9,10'
$CommaDelimArray = Split($CommaDelimString,',')
For Each $Element In $CommaDelimArray
$Element ?
Next



Chris S.
(MM club member)
2005-04-29 08:12 PM
Re: Coma delimited files

Just remember that some fields can contain commas that will cause problems using SPLIT.

Code:

ado.csv

Name,Position,ID
"Blow, Joe",User,10001
"Doe, Mary",User,10002
"Doe, John",Admin,10003



In the above sample it may be beneficial to open the CSV using ADODB.

Code:

$adOpenStatic = 3
$adLockOptimistic = 3
$adCmdText = &1

$objConnection = CreateObject("ADODB.Connection")
$objRecordSet = CreateObject("ADODB.Recordset")

$sPathtoTextFile = "g:\"

$objConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + $sPathtoTextFile + ";" +
'Extended Properties="text; HDR=YES; FMT=Delimited"')

$objRecordset.Open("SELECT * FROM ado.csv",
$objConnection,$adOpenStatic,$adLockOptimistic,$adCmdText)

Do
$objRecordset.Fields("Name").Value ?
$objRecordset.Fields("Position").Value ?
$objRecordset.Fields("ID").Value ?
$objRecordset.MoveNext
Until $objRecordset.EOF

$objRecordSet.Close
$objConnection.Close

ShawnAdministrator
(KiX Supporter)
2005-04-29 08:59 PM
Re: Coma delimited files

Chris - nice - that script's a keeper ! Was looking for something like this.

Now if I can only get your Active Directory browser script working in my domain. Not too sure why every time I start it, it doesn't do anything.


normandbr
(Fresh Scripter)
2005-04-29 10:33 PM
Re: Coma delimited files

LES, they print on the screen but how to put them in variable.

Les
(KiX Master)
2005-04-29 11:06 PM
Re: Coma delimited files

Code:
break on
$CommaDelimString = '1,2,3,4,5,6,7,8,9,10'
$CommaDelimArray = Split($CommaDelimString,',')

For $Index = 0 to UBound($CommaDelimArray)
$CommaDelimArray[$Index] ?
Next

$element0 = $CommaDelimArray[0]
$element1 = $CommaDelimArray[1]

$element0 ?



ShawnAdministrator
(KiX Supporter)
2005-04-29 11:35 PM
Re: Coma delimited files

awwwhhh, Chris didn't take the bait :0(

normandbr
(Fresh Scripter)
2005-04-30 02:19 AM
Re: Coma delimited files

Thanks a lot LES, As you can see I am a rookie with kixtart.

Les
(KiX Master)
2005-04-30 02:39 AM
Re: Coma delimited files

Ja, well... you disappointed Shawn by not snapping up Chris' most excellent ADODB code.

Chris,
Pure poetry in coding... brings a tear to my eye. Your daddy must be proud.


NTDOCAdministrator
(KiX Master)
2005-04-30 05:41 AM
Re: Coma delimited files

For plenty of methods of transferring data with ADO

INFO: Methods for Transferring Data to Excel from Visual Basic


ShawnAdministrator
(KiX Supporter)
2005-04-30 05:13 PM
Re: Coma delimited files

Didn't say it was poetry in coding, just that it was a precipitous bit of code for a scripty I'm doin. ;0)

Les
(KiX Master)
2005-04-30 05:22 PM
Re: Coma delimited files

Not putting words in your mouth... them thar words wuz mine. Every time I think I am getting fairly proficient at coding, along comes Bryce or Chris and humble me.

Sealeopard
(KiX Master)
2005-04-30 11:08 PM
Re: Coma delimited files

You could even use the DB...() UDFs to read select fields out of a CSV file by using the connection string for a CVS file.

NTDOCAdministrator
(KiX Master)
2005-05-01 03:33 AM
Re: Coma delimited files

Wow - Did I hear right (humble me), from Les