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!

READ csv fsrt way...

sal21

Programmer
Apr 26, 2004
462
IT
I use this code:

Rich (BB code):
Option Explicit
Public Function QuickRead(FName As String) As Variant

    Dim I As Long
    Dim RES As String
    Dim L As Long
    Dim V As Variant

    I = FreeFile
    L = FileLen(FName)
    RES = Space(L)
    Open FName For Binary Access Read As #I
    Get #I, , RES
    Close I

    QuickRead = Split(RES, vbLf)

End Function
Public Sub FAST_READ()

    Dim strFilePathName As String
    strFilePathName = "C:\Lavori_Vb6\IMPORT_STRADE\CSVFILE\" & NOMEFILE
    Dim strFileLine As String, RIGA As String, CF As String, ISTAT As String, STRADA As String, CIVICO As String, IDSTR As String
    Dim V As Variant
    Dim I As Long

    V = QuickRead(strFilePathName)

    For I = 1 To UBound(V) - 1
    
        DoEvents

        RIGA = V(I)

        IDSTR = Split(RIGA, ";")(2)

        RSS.Seek IDSTR, adSeekFirstEQ
        If RSS.EOF Then

            CF = Split(RIGA, ";")(0)
            ISTAT = Split(RIGA, ";")(1)
            IDSTR = Split(RIGA, ";")(2)
            STRADA = Split(RIGA, ";")(4)

            SQL = "INSERT INTO STRADE (CF, ISTAT, ID, STRADA, AGG) VALUES ('" & CF & "', '" & ISTAT & "','" & IDSTR & "','" & Replace(STRADA, "'", "''") & "','" & Date & "')"
            CON.Execute (SQL)
            'CIVICO = Split(RIGA, ";")(10)

        End If

    Next I

End Sub

for a little file work well but with a big file have in Res out of memory...

Have a suggestion?
 
Since you are inserting into the db line by line, you might as well read it from the source file line by line
 
Hi Bro
Based thie link in my prevoius post:

Download zio file from web looping ecc...

Download the LOMBARDIA zip file Indirizzario

IS One very big file
 
No, I mean it isn't that big for VB6 to handle. However, you sometimes have to be careful about how you allocate memory (via buffers or strings), as they have some limitations; oddly current versions of VBA are somewhat better in this regard.

This is one of the reasons it may be better to read the file one line at a time.
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top