[AccessD] Import CSV file with Unix end of line characters

Stuart McLachlan stuart at lexacorp.com.pg
Wed Oct 27 07:49:25 CDT 2004


On 27 Oct 2004 at 13:14, Paul Hartland (ISHARP) wrote:

> To all,
>  
> Could someone please tell me or send me some sample code on the best way to
> import a CSV file which has Unix end of line characters.
>  


Here's the PowerBasic code for a simple converter I use for this. You could 
probably do the same thing in VBA  with a few minor mods. I can let you 
have the compiled  executable if you want it.


FUNCTION PBMAIN() AS LONG
DIM infile AS STRING
DIM outfile AS STRING
DIM temp AS STRING

    infile = COMMAND$
    IF DIR$(infile) = "" THEN
        MSGBOX infile & " not found"
        EXIT FUNCTION
    END IF
    OPEN infile$ FOR BINARY AS #1
    GET$ #1, LOF(1), temp
    IF INSTR(temp,CHR$(13,10)) > 0 THEN
         MSGBOX "This file is already DOS formatted!"
    ELSE
       REPLACE CHR$(10) WITH CHR$(13,10) IN temp
       outfile = LEFT$(infile,LEN(infile)-4) & "-DOS.CSV"
       OPEN outfile$ FOR BINARY AS #2
       PUT$ #2, temp
       MSGBOX Infile & " converted to " & outfile
       CLOSE #2
    END IF
    CLOSE #1

END FUNCTION            0

-- 
Stuart





More information about the AccessD mailing list