Coder Social home page Coder Social logo

Bug about vba-csv HOT 7 CLOSED

sdkn104 avatar sdkn104 commented on August 20, 2024
Bug

from vba-csv.

Comments (7)

sdkn104 avatar sdkn104 commented on August 20, 2024

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 ?

from vba-csv.

ws-garcia avatar ws-garcia commented on August 20, 2024

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.

from vba-csv.

ws-garcia avatar ws-garcia commented on August 20, 2024

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.

from vba-csv.

ws-garcia avatar ws-garcia commented on August 20, 2024

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.

from vba-csv.

sdkn104 avatar sdkn104 commented on August 20, 2024

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.

from vba-csv.

ws-garcia avatar ws-garcia commented on August 20, 2024

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)

from vba-csv.

ws-garcia avatar ws-garcia commented on August 20, 2024

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!

from vba-csv.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.