Page 1 of 1 1
Topic Options
#138861 - 2005-04-29 04:24 AM Coma delimited files
normandbr Offline
Fresh Scripter

Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
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 ???
Top
#138862 - 2005-04-29 05:04 AM Re: Coma delimited files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It is done exactly the same except you Split() on the comma. Show us your code and a sample of the file.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138863 - 2005-04-29 06:04 PM Re: Coma delimited files
normandbr Offline
Fresh Scripter

Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
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

Top
#138864 - 2005-04-29 06:13 PM Re: Coma delimited files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138865 - 2005-04-29 08:12 PM Re: Coma delimited files
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
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
Top
#138866 - 2005-04-29 08:59 PM Re: Coma delimited files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.

Top
#138867 - 2005-04-29 10:33 PM Re: Coma delimited files
normandbr Offline
Fresh Scripter

Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
LES, they print on the screen but how to put them in variable.
Top
#138868 - 2005-04-29 11:06 PM Re: Coma delimited files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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 ?

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138869 - 2005-04-29 11:35 PM Re: Coma delimited files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
awwwhhh, Chris didn't take the bait :0(
Top
#138870 - 2005-04-30 02:19 AM Re: Coma delimited files
normandbr Offline
Fresh Scripter

Registered: 2004-05-17
Posts: 19
Loc: Montreal, canada
Thanks a lot LES, As you can see I am a rookie with kixtart.
Top
#138871 - 2005-04-30 02:39 AM Re: Coma delimited files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138872 - 2005-04-30 05:41 AM Re: Coma delimited files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
For plenty of methods of transferring data with ADO

INFO: Methods for Transferring Data to Excel from Visual Basic

Top
#138873 - 2005-04-30 05:13 PM Re: Coma delimited files
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Didn't say it was poetry in coding, just that it was a precipitous bit of code for a scripty I'm doin. ;0)
Top
#138874 - 2005-04-30 05:22 PM Re: Coma delimited files
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138875 - 2005-04-30 11:08 PM Re: Coma delimited files
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#138876 - 2005-05-01 03:33 AM Re: Coma delimited files
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Wow - Did I hear right (humble me), from Les
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 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.069 seconds in which 0.024 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