Here is a UDF which should work in all situations. It returns an array containing each field from the line:


Function fnCSV2Array($s)
Dim $iIndex,$iLength,$cChar,$iMode,$iArraySize
Redim Preserve $fnCSV2Array[0]
$iArraySize=0
$iMode=0 ; 1 = in quoted field

$iLength=Len($s)
For $iIndex = 1 To $iLength
$cChar=SubStr($s,$iIndex,1)
If $iMode
If $cChar='"'
If SubStr($s,$iIndex+1,1)='"'
$fnCSV2Array[$iArraySize]=""+$fnCSV2Array[$iArraySize]+$cChar
$iIndex=$iIndex+1
Else
$iMode=0
EndIf
Else
$fnCSV2Array[$iArraySize]=""+$fnCSV2Array[$iArraySize]+$cChar
EndIf
Else
Select
Case $cChar=','
$iArraySize=$iArraySize+1
Redim Preserve $fnCSV2Array[$iArraySize]
Case $cChar='"'
$iMode=1
Case "true"
$fnCSV2Array[$iArraySize]=""+$fnCSV2Array[$iArraySize]+$cChar
EndSelect
EndIf
Next
EndFunction


Here is an example of how to use it:


For Each $sElement In fnCSV2Array('The following field contains a comma,"Doe, John"')
"<" $sElement "> "
Next
?


[ 31. January 2003, 15:23: Message edited by: Richard H. ]