Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 & Reading CSV file with data having spaces

Status
Not open for further replies.

sam4help

Programmer
Jul 22, 2011
74
AE
Dear All,

I am into trouble while reading .csv file having spaces.

I am reading csv file with below code;
SAMPLE INPUT FILE:

AAAA,43438894322,USA,BASIC
BBBB,73738 9393 939,INDIA,BASIC
CCCC,00293993020,UK,PREMIUM

all is well until i get any file with data having space like
01 0002 020929
65650002 543

Code:
Dim connCSV As New ADODB.Connection
Dim rsCSV As New ADODB.Recordset
     
connCSV.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
     & Path & ";Extended Properties='text;HDR=" & hasHeader & ";FMT=Delimited'"
    
rsCSV.Open "Select * From " & fileName, _
    connCSV, adOpenStatic, adLockReadOnly, adCmdText
          Do While Not rsCSV.EOF()
                 cntRows = cntRows + 1
                     With MSFlexGrid1
                          currRow = .Rows - 1
                         
                         .TextMatrix(currRow, 1) = IIf(IsNull(rsCSV.Fields(0).Value), "", rsCSV.Fields(0).Value)
                         .TextMatrix(currRow, 2) = rsCSV.Fields(1).Value
                         .TextMatrix(currRow, 3) = Format(rsCSV.Fields(2).Value, "####.000")
                         .TextMatrix(currRow, 4) = PadRight(Left(rsCSV.Fields(3).Value, 8), "XXXXXXXX")
                         .TextMatrix(currRow, 5) = IIf(IsNull(rsCSV.Fields(4).Value), "", rsCSV.Fields(4).Value)
                         .TextMatrix(currRow, 6) = rsCSV.Fields(5).Value
                         .TextMatrix(currRow, 7) = rsCSV.Fields(6).Value
                         
                         .Rows = .Rows + 1
                     End With
             rsCSV.MoveNext
             Loop

The place where its 01 0002 020929 it is returning NULL where as there is data available. Same if its alphanumeric like OXFORD UNIVERSITY it returns correct, but in case of numbers it returns NULL.

Any help will be appreciated,

Best Regards,

Sam
 
yea, correct.
By that time I had started working with that sample file, so we were on same route. Thanks Again strongm & all others who extended help.

Best Regards,

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top