Results 1 to 12 of 12

Thread: [SOLVED] Parsing CSV is randomly slow

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    Resolved [SOLVED] Parsing CSV is randomly slow



    i've write a code that import a csv file in an excel worksheet

    the code works fine but, with the same csv file, the speed of the tests are sometimes very quick and other times very slow

    here is my code :


    Code:
    Sub Import_CSV()
        Dim pcti As Single, pctj As Single, dept As Single
        
        pcti = Timer
        pctj = Timer
        dept = Timer
        
        'here i select my csv file
        FileToOpen = Application.GetOpenFilename("Fichier CSV (*.csv), *.csv", , "Sélectionner le fichier à importer ...", , False)
        If FileToOpen = False Then
            Exit Sub
        End If
        
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set Fichier = objFSO.OpenTextFile(FileToOpen, 1, True)
        
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set ts = fs.OpenTextFile(FileToOpen, 1, False)
        
        Application.ScreenUpdating = False
        
        i = 1
        Do Until Fichier.AtEndOfStream
            j = i - 1
            tab_line = Split(Fichier.ReadLine, ";")
        
            If i >= 2 Then
                Feuil1.Range("A" & j).Value = tab_line(0)
                Feuil1.Range("B" & j).Value = tab_line(1)
                Feuil1.Range("C" & j).Value = tab_line(2)
                Feuil1.Range("D" & j).Value = tab_line(3)
                Feuil1.Range("E" & j).Value = tab_line(4)
                Feuil1.Range("F" & j).Value = tab_line(5)
                Feuil1.Range("G" & j).Value = tab_line(6)
            End If
    
            i = i + 1
        Loop
    
        'here i clear the unwated cells
        j = i - 1
        Feuil1.Range("A" & G, "J65000").ClearContents
        
        Application.ScreenUpdating = True
        Unload u_progression
    End Sub
    my csv file is semicolon formated
    and contains about 8000 lines
    exemple :
    Code:
    Nbre;dtehre;Heures;Debits Sens 1;Données Reconstituées; Données (année - 1);ID
    1;2009-03-05 00:00:00;00;0;49;49;38611
    2;2009-03-05 01:00:00;01;0;20;20;38612
    3;2009-03-05 02:00:00;02;0;28;28;38613
    4;2009-03-05 03:00:00;03;0;15;15;38614
    5;2009-03-05 04:00:00;04;0;7;7;38615
    6;2009-03-05 05:00:00;05;0;7;7;38616
    .....
    .....
    with the same file, sometimes it take 1 minute max, and sometimes about 20min
    and it seems its very randomly (i tried to quit and execute excel, boot and reboot computer, etc ...) but never be able to find a cause

    so maybe its something in the code, maybe is there something i ccan inprove

    thanks to help
    bye
    Last edited by schlagg; Mar 15th, 2010 at 03:31 AM. Reason: solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width