Reading csv file and parsing comma delimited values in Array

  • Thread starter mls via AccessMonster.com
  • Start date
M

mls via AccessMonster.com

I am reading a .CSV file using FileSystemObject, and one of my field (std_num
) which has null values for the first 15 rows but have a number value after
16 so how can I read that correctly?

Dim myarray() As String
Dim temp_str As String
Dim SET1 As String
Dim STD_num As Integer

temp_str = "A1,NTC,H1,Unknown,Undetermine" ' First 15 rows
temp_str = "A1,NTC,H1,Unknown,20.3, 25.34" ' 16th row
myarray = Split(temp_str, ",")

SET1 = myarray(2)
If (IsNumeric(myarray(5))) Then
STD_num = Format(myarray(5), "####.##")
Else
STD_num = 0
End If
 
T

Tom van Stiphout

On Wed, 03 Feb 2010 21:45:30 GMT, "mls via AccessMonster.com"

If I understand you correctly you sometimes have 5, sometimes 6 values
in a row. So test for that:
myarray = split(...)
if ubound(myarray)=4 then
'5 elements
else if ubound(myarray) = 5 then
'6 elements
else
debug.assert false 'unexpected count
end if

-Tom.
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top