Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #3

Closed
ws-garcia opened this issue Oct 2, 2020 · 7 comments
Closed

Bug #3

ws-garcia opened this issue Oct 2, 2020 · 7 comments

Comments

@ws-garcia
Copy link

Currently, I am improving the CSVinterface class to make it RFC4180 standard fully compliant. As you know, your well developed project is used by me as a reference.

I test your code using the following CSV text and the returned value by your ParseCSVToArray function is null:

"Field with 
multiple lines" , "Another field 
with some 
line breaks inside" , "Include some  comma, for test" , Normal field here
1, 2, 3 ,4 
"Field 1", "Field 2" , Field 3 , "Field 4"

The above CSV complies the RFC4180 standard.

@sdkn104
Copy link
Owner

sdkn104 commented Oct 3, 2020

Thank you for reporting.
I tired your CSV text but ParseCSVToArray does not return null.
I have tried both case of return code CR and CRLF.
My test code is:

    Dim csv As Variant
    Dim csvText As String
    csvText = readFile("C:\Users\xxxx\desktop\test.txt")  'readFile is defined in CSVUtils_Example.
    csv = ParseCSVToArray(csvText)
    If IsNull(csv) Then
        Debug.Print Err.Number & " (" & Err.Source & ") " & Err.Description
    End If

"test.txt" contains your CSV text.
What is your situation ?

@ws-garcia
Copy link
Author

The CSV text is on a ANSI codified file, when I tried to parse it, using your well documented code, I got an null value returned.

@ws-garcia
Copy link
Author

First, I defined SDKNstrArray As Variant ; and then I make a call SDKNstrArray = ParseCSVToArray(tmpCSV), were the argument was defined as tmpCSV As String. The inspection window show me the null value returned after call the function.

@ws-garcia
Copy link
Author

After a look to your response:

SDKNstrArray = ParseCSVToArray(tmpCSV) 
If IsNull(SDKNstrArray) Then 
    Debug.Print Err.Number & " (" & Err.Source & ") " & Err.description 
End If

The above prints the text 10001 (ParseCSVToCollection) Syntax Error in CSV: numbers of fields are different among records in the immediate window.

@sdkn104
Copy link
Owner

sdkn104 commented Oct 3, 2020

I tried the following code.

    Dim csv As Variant
    Dim csvText As String
    csvText = """Field with" & vbCr & _
                "multiple lines"" , ""Another field" & vbCr & _
                "With some" & vbCr & _
                "line breaks inside"" , ""Include some  comma, for test"" , Normal field here" & vbCr & _
                "1, 2, 3 ,4" & vbCr & _
                """Field 1"", ""Field 2"" , Field 3 , ""Field 4"""
    Debug.Print csvText
    csv = ParseCSVToArray(csvText)
    If IsNull(csv) Then
        Debug.Print Err.Number & " (" & Err.Source & ") " & Err.Description
    End If
    Debug.Print UBound(csv, 1)
    Debug.Print UBound(csv, 2)

The result in immediate window is

"Field with
multiple lines" , "Another field
With some
line breaks inside" , "Include some  comma, for test" , Normal field here
1, 2, 3 ,4
"Field 1", "Field 2" , Field 3 , "Field 4"
 3 
 4 

Please check it.

@ws-garcia
Copy link
Author

ws-garcia commented Oct 3, 2020

The file has some space chars not included in your above test:
"Field with
multiple lines" ,"Another field
with some
line breaks inside" , "Include some comma, for test" , Normal field here
1, 2, 3 ,4
"Field 1", "Field 2" , Field 3 , "Field 4"

But, I think the main problem here is that the file actually use vbCrLf instead vbCr char

However, I will check if there are additional vbCrLf chars in the CSV file that potential may cause the cited error in your code.
Captura de pantalla (86)

@ws-garcia
Copy link
Author

ws-garcia commented Oct 3, 2020

Definitely, the are an extra vbCrLf char into the CSV file. This file issue break the logic and generate an error. After remove it, your code successful import the data. Thanks for your replies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants