View Single Post
Old 2nd March 2017, 18:16   #381  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
RT_Stats v2.0 Beta 07, new version, see MediaFire (or SendSpace) in sig below this post.

Code:
	v2.0 Beta 5. Added RT_DBaseReadCSV().
	v2.0 Beta 6. 28 Feb 2017.
		RT_DBaseReadCSV(), relaxed Separator requirement if SPACE/TAB separated. Added StrDelimiter string Arg.
	v2.0 Beta 7. 02 Mar 2017.
		RT_DBaseReadCSV(), Added StartField and EndField args. Max CSV line length increased to 64*1024 bytes.

Code:
RT_DBaseReadCSV(String DB, String CSV, String "Separator"=",",String "StrDelimiter"="\"",Int "StartField"=0,Int "EndField"=last_field)

    This function will extract CSV values in text file, and append them as records to an appropriately formatted DBase file.

    DB,           FileName of an RT_Stats DBase file.
    CSV,          FileName of a text CSV (Comma Separated Value) file.
    Separator     Default "," ie comma separator (first character only, Chr()'s 0, 13, 10, and 34 [Double Quote] illegal).
                  Default Separator "," (Comma) is optional and so long as CSV values are SPACE/TAB separated will not produce an error if separator is missing.
    StrDelimiter  Default = "\"" ie single character string Double Quote.
                  StrDelimiter (String Delimiter) can be multiple characters (empty string "" illegal, also cannot contain the Separator character nor
                  SPACE or TAB), Default is a Double Quote single character string.
                  CSV string values CANNOT contain StrDelimiter string, ie for default StrDelimiter, strings cannot contain a double quote character string.
                  So long as the StrDelimiter does not appear within any string, nearly any StrDelimiter can be used, eg "@@@" is a 3 character StrDelimiter
                  that you could use in place of double quote string delimiters, where the string values could then contain a double quote character, in
                  such a case you should enclosed CSV strings as in @@@Some text that contains a " double quote.@@@.
                  NOTE, StrDelimiter IS case sensitive, so if using alphabetic characters they have to match exactly.
                  
    StartField    Default = 0.
    EndField      Default = last field in DBase record (By default, all fields should be present in CSV file, else error).
                  Above StartField and EndField args allow setting of limited number of CONSECUTIVE fields within a record, the remaining
                  fields if any are set to NULL values, ie String all zero chars, bool = false, Float=0.0, int and bin=0.

    Function returns Int, the number of records added to the DBase.
    (Maximum line length in CSV text file is 64*1024 characters).

    Example:-
        CSV.txt file containing text something like this
        ###
            1  ,42.0 ,true , "Hello"        # I am a comment
            2  ,43.5 ,false, "Goodbye"
            $FF,3.142,TRUE , "Coconuts"     # So Am I
        ###
        Script:-
        DB  = "My.DB"
        CSV = "CSV.txt"
        RT_DBaseAlloc(DB,0,"ifbs32")        # Allocate DBase with 0 pre-allocated records, 4 fields, 0)=Int, 1)=Float, 2)=bool, 3=String(maxlen=32).
        Added=RT_DBaseReadCSV(DB,CSV)
        Return MessageClip("Added "+String(Added)+" Records")   # Shows "Added 3 Records".
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote