You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CSV, stands from Comma Separated Values, files are special kind of tabulated plain text data widely used in data exchange. There is no globally accepted standard format for that kind of files, however, out there are well formed standards such as [RFC4180](https://www.ietf.org/rfc/rfc4180.txt) proposed by The Internet Society.
14
14
Although many solutions has been developed for work with CSV files into VBA, including projects from [@sdkn104](https://github.com/sdkn104/VBA-CSV) and [@Senipah](https://github.com/Senipah/VBA-Better-Array) on Github, the vast majority of these have serious performance lacks. This argumentations conduce to the development of a VBA class module that allows users exchange data between VBA arrays and CSV files at relatively high speed.
15
15
### Advantages
16
-
*CSVfileManager can work with like RFC4180 CSV standard (there are few differences).
16
+
*CSVinterface can work with like RFC4180 CSV standard (there are few differences).
17
17
* User have the option to import only certain range of records from given CSV file.
18
18
* Writes and reads files at high speed.
19
19
## Philosophy
20
-
The VBA CSVfileManager class module is designed for gain advantage from the well structured CSV files, this means, there isn't automatic syntax check, given the user decide how the class will works. This can be seen as a weakness, but the class get a speed-up on writing and reading procedures at time the user controls how the file is interpreted, keeping in mind that, in fact, VBA is a language with slow code execution speed.
20
+
The VBA CSVinterface class module is designed for gain advantage from the well structured CSV files, this means, there isn't automatic syntax check, given the user decide how the class will works. This can be seen as a weakness, but the class get a speed-up on writing and reading procedures at time the user controls how the file is interpreted, keeping in mind that, in fact, VBA is a language with slow code execution speed.
21
21
Under this idealization it's easy to develop a solution that implicity complies with the RFC4180 standart for user specified CSV document format. In order to achieve this, the user must to follow the rules specified below.
22
22
## Rules
23
23
1. Each record is located on a separate line, delimited by a line break (CRLF, CR, LF).
@@ -29,36 +29,36 @@ Under this idealization it's easy to develop a solution that implicity complies
29
29
## Usage
30
30
Import whole CSV file into an VBA array
31
31
```vbscript
32
-
DimCSVmanagerAsCSVfileManager
32
+
DimCSVixAsCSVinterface
33
33
DimMyArrayAsvariant
34
-
SetCSVmanager=NewCSVfileManager
35
-
CallCSVmanager.OpenConnection(fileName)
36
-
CallCSVmanager.ImportFromCSV
37
-
MyArray=CSVmanager.CSVdata
38
-
SetCSVmanager=Nothing
34
+
SetCSVix=NewCSVinterface
35
+
CallCSVix.OpenConnection(fileName)
36
+
CallCSVix.ImportFromCSV
37
+
MyArray=CSVix.CSVdata
38
+
SetCSVix=Nothing
39
39
```
40
40
Import a range of records from CSV file into a VBA array
41
41
```vbscript
42
-
DimCSVmanagerAsCSVfileManager
42
+
DimCSVixAsCSVinterface
43
43
DimMyArrayAsvariant
44
-
SetCSVmanager=NewCSVfileManager
45
-
CSVmanager.StartingRecord=10
46
-
CSVmanager.EndingRecord=20
47
-
CallCSVmanager.OpenConnection(fileName)
48
-
CallCSVmanager.ImportFromCSV
49
-
MyArray=CSVmanager.CSVdata
50
-
SetCSVmanager=Nothing
44
+
SetCSVix=NewCSVinterface
45
+
CSVix.StartingRecord=10
46
+
CSVix.EndingRecord=20
47
+
CallCSVix.OpenConnection(fileName)
48
+
CallCSVix.ImportFromCSV
49
+
MyArray=CSVix.CSVdata
50
+
SetCSVix=Nothing
51
51
```
52
52
Set the char to encapsulate, coerce, fields
53
53
```vbscript
54
-
CSVmanager.EscapeChar=NotEscape
55
-
CSVmanager.EscapeChar=Apostrophe
56
-
CSVmanager.EscapeChar=DoubleQuotes
54
+
CSVix.EscapeChar=NullChar
55
+
CSVix.EscapeChar=Apostrophe
56
+
CSVix.EscapeChar=DoubleQuotes
57
57
```
58
58
Set fields and records delimiters
59
59
```vbscript
60
-
CSVmanager.FieldsDelimiter=";"
61
-
CSVmanager.RecordsDelimiter=vbCrLf
60
+
CSVix.FieldsDelimiter=";"
61
+
CSVix.RecordsDelimiter=vbCrLf
62
62
```
63
63
## Benchmark
64
64
The class was tested against many solutions using the oldest, lowest-processing capacity laptop I could find: Win 7 Starter 32-bit, Intel® Atom™ CPU N2600 @1.60 GHz, 1 GB RAM.
@@ -72,7 +72,7 @@ The times showed, seconds, in the bellow table are the average of ten (10) calls
Considering the system specification for the test machine (4 MB/sec. when it writes files to an USB), the above times was stunning!: up to 2.69 MB/sec. for reading operations.
75
+
Considering the system specification for the test machine (4 MB/sec. when it writes files to an USB), the above times was stunning!: up to 2.75 MB/sec. for reading operations.
0 commit comments