Skip to content

Commit 42d0398

Browse files
committed
Update source, update examples
1 parent 549f7f7 commit 42d0398

File tree

4 files changed

+355
-226
lines changed

4 files changed

+355
-226
lines changed

docs/examples/exportation-examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Sub ExportToCSV_RFC4180()
2828
tmpCSV = CSVix.GetDataFromCSV(filePath) 'Store CSV file's content.
2929
CSVix.EndingRecord = 10 'Sets the importation ending
3030
Call CSVix.ImportFromCSVString(tmpCSV) 'Import the range of records
31-
Call CSVix(MyArray) 'Dumps the data to array
31+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
3232
'@---------------------------------------------------------------------------------
3333
' Exportation code block start
3434
Call CSVix.OpenConnection(outputFile, DeleExistingFile:=True) 'Open a physical connection to the CSV file
@@ -63,7 +63,7 @@ Sub ExportToCSV()
6363
tmpCSV = CSVix.GetDataFromCSV(filePath) 'Store CSV file's content.
6464
CSVix.EndingRecord = 10 'Sets the importation ending
6565
Call CSVix.ImportFromCSVString(tmpCSV) 'Import the range of records
66-
Call CSVix(MyArray) 'Dumps the data to array
66+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
6767
'@---------------------------------------------------------------------------------
6868
' Exportation code block start
6969
Call CSVix.OpenConnection(outputFile, DeleExistingFile:=True) 'Open a physical connection to the CSV file
@@ -97,7 +97,7 @@ Sub ExportToCSV()
9797
tmpCSV = CSVix.GetDataFromCSV(filePath) 'Store CSV file's content.
9898
CSVix.EndingRecord = 10 'Sets the importation ending
9999
Call CSVix.ImportFromCSVString(tmpCSV) 'Import the range of records
100-
Call CSVix(MyArray) 'Dumps the data to array
100+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
101101
'@---------------------------------------------------------------------------------
102102
' Exportation code block start
103103
Call CSVix.OpenConnection(outputFile, DeleExistingFile:=True) 'Open a physical connection to the CSV file

docs/examples/fileconversion.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Sub ExportToCSV_RFC4180()
3030
tmpCSV = CSVix.GetDataFromCSV(filePath) 'Store CSV file's content.
3131
CSVix.EndingRecord = 10 'Sets the importation ending
3232
Call CSVix.ImportFromCSVString(tmpCSV) 'Import the range of records
33-
Call CSVix(MyArray) 'Dumps the data to array
33+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
3434
'@---------------------------------------------------------------------------------
3535
' Exportation code block start
3636
CSVix.FieldsDelimiter = vbTab
@@ -60,7 +60,7 @@ Sub ExportToCSV_RFC4180()
6060
tmpCSV = CSVix.GetDataFromCSV(filePath) 'Store TSV file's content.
6161
CSVix.EndingRecord = 10 'Sets the importation ending
6262
Call CSVix.ImportFromCSVString(tmpCSV) 'Import the range of records
63-
Call CSVix(MyArray) 'Dumps the data to array
63+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
6464
'@---------------------------------------------------------------------------------
6565
' Exportation code block start
6666
CSVix.FieldsDelimiter = ","

docs/examples/importation-examples.md

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Sub ImportRecords_RFC4180()
2525
Set CSVix = New CSVinterface 'Create new instance
2626
Call CSVix.OpenConnection(filePath) 'Open a physical connection to the CSV file
2727
Call CSVix.ImportFromCSV 'Import data
28-
Call CSVix(MyArray) 'Dumps the data to array
28+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
2929
Set CSVix = Nothing 'Terminate the current instance
3030
End Sub
3131
```
@@ -51,7 +51,7 @@ Sub ImportTopTenRecords_RFC4180()
5151
CSVix.EndingRecord = 10 'Sets the importation ending
5252
Call CSVix.OpenConnection(filePath) 'Open a physical connection to the CSV file
5353
Call CSVix.ImportFromCSV 'Import the range of records
54-
Call CSVix(MyArray) 'Dumps the data to array
54+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
5555
Set CSVix = Nothing 'Terminate the current instance
5656
End Sub
5757
```
@@ -74,7 +74,7 @@ Sub ImportTopTenRecords_RFC4180()
7474
tmpCSV = CSVix.GetDataFromCSV(filePath) 'Store CSV file's content.
7575
CSVix.EndingRecord = 10 'Sets the importation ending
7676
Call CSVix.ImportFromCSVString(tmpCSV, HeadersOmission:=True) 'Import the range of records omitting the headers
77-
Call CSVix(MyArray) 'Dumps the data to array
77+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
7878
Set CSVix = Nothing 'Terminate the current instance
7979
End Sub
8080
```
@@ -100,7 +100,7 @@ Sub ImportTenMiddleRecords_RFC4180()
100100
CSVix.StartingRecord = 11 'Sets the importation ending
101101
CSVix.EndingRecord = 20 'Sets the importation ending
102102
Call CSVix.ImportFromCSVString(tmpCSV, HeadersOmission:=True) 'Import the range of records omitting the headers
103-
Call CSVix(MyArray) 'Dumps the data to array
103+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
104104
Set CSVix = Nothing 'Terminate the current instance
105105
End Sub
106106
```
@@ -131,7 +131,7 @@ Sub ImportRecords()
131131
CSVix.QuotingMode = QuotationMode.All 'Alter behavior for escaped files
132132
CSVix.EscapeToken = EscapeTokens.NullChar 'Specify that CSV file has neither field needing to be escaped.
133133
Call CSVix.ImportFromCSV 'Import data
134-
Call CSVix(MyArray) 'Dumps the data to array
134+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
135135
Set CSVix = Nothing 'Terminate the current instance
136136
End Sub
137137
```
@@ -141,7 +141,7 @@ The \[EXAMPLE6\] shows how you can dump the imported data to an Excel Worksheet.
141141
Sub ImportRecords_RFC4180()
142142
Dim CSVix As CSVinterface
143143
Dim filePath As String
144-
144+
145145
filePath = "C:\Demo_Headed_400k_records.csv" 'Change this to suit your needs
146146
Set CSVix = New CSVinterface 'Create new instance
147147
Call CSVix.OpenConnection(filePath) 'Open a physical connection to the CSV file
@@ -172,7 +172,72 @@ Sub ImportRecords()
172172
CSVix.QuotingMode = QuotationMode.All 'Alter behavior for escaped files
173173
CSVix.EscapeToken = EscapeTokens.DoubleQuotes 'Specify that all fields need to be escaped.
174174
Call CSVix.ImportFromCSV 'Import data
175-
Call CSVix(MyArray) 'Dumps the data to array
175+
Call CSVix.DumpToArray(MyArray) 'Dumps the data to array
176+
Set CSVix = Nothing 'Terminate the current instance
177+
End Sub
178+
```
179+
180+
The \[EXAMPLE8\] shows how you can loop through all the CSV imported data from the current VBA-CSV interface class instance.
181+
182+
See also
183+
: [VectorsBound property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/vectorsbound.html), [RectangularResults property](https://ws-garcia.github.io/VBA-CSV-interface/api/properties/rectangularresults.html).
184+
185+
```vb
186+
Sub LoopThroughImportedRecords()
187+
Dim CSVix As CSVinterface
188+
Dim MyArray() As String
189+
Dim filePath As String
190+
191+
filePath = "C:\Demo_Headed_400k_records.csv" 'Change this to suit your needs
192+
Set CSVix = New CSVinterface 'Create new instance
193+
Call CSVix.OpenConnection(filePath) 'Open a physical connection to the CSV file
194+
Call CSVix.ImportFromCSV 'Import data
195+
'@--------------------------------------------------------------------
196+
' Loop through imported data. SAVE TO 2-DIMENSIONAL ARRAY.
197+
Dim WGstrArray() As String, vCollection As Collection
198+
Dim i As Long, j As Long, k As Long
199+
Dim CurJaggedIndex As Long, CurJaggedSize As Long
200+
Dim JaggedCounter As Long, WGvarArray() As Variant
201+
202+
If CSVix.RectangularResults Then 'The internal array is rectangular
203+
ReDim WGstrArray(0 To CSVix.Count - 1, 0 To CSVix.VectorsBound)
204+
Else
205+
ReDim WGstrArray(0 To CSVix.Count - 1, 0 To CSVix.VectorsMaxBound)
206+
Set vCollection = CSVix.IrregularVectors
207+
JaggedCounter = 1
208+
CurJaggedIndex = vCollection.Item(JaggedCounter)(0)
209+
CurJaggedSize = vCollection.Item(JaggedCounter)(1)
210+
End If
211+
'Access Items one by one
212+
For i = 0 To UBound(WGstrArray)
213+
For j = 0 To CSVix.VectorsBound
214+
WGstrArray(i, j) = CSVix.Item(i, j)
215+
Next j
216+
If Not CSVix.RectangularResults Then
217+
If i = CurJaggedIndex Then
218+
k = j
219+
Do
220+
WGstrArray(i, k) = CSVix.Item(i, k)
221+
k = k + 1
222+
Loop While k <= CurJaggedSize
223+
JaggedCounter = JaggedCounter + 1
224+
If JaggedCounter <= vCollection.Count Then
225+
CurJaggedIndex = vCollection.Item(JaggedCounter)(0)
226+
CurJaggedSize = vCollection.Item(JaggedCounter)(1)
227+
End If
228+
End If
229+
End If
230+
Next i
231+
If CSVix.ErrNumber <> 0 Then Debug.Print "#Error:"; CSVix.ErrNumber, "Desc.:"; CSVix.ErrDescription
232+
'@--------------------------------------------------------------------
233+
' Loop through imported data. SAVE TO JAGGED ARRAY.
234+
'Redim the array
235+
ReDim WGvarArray(0 To CSVix.Count - 1)
236+
For i = 0 To UBound(WGvarArray)
237+
For j = 0 To CSVix.VectorsBound
238+
WGvarArray(i) = CSVix.Item(i)
239+
Next j
240+
Next i
176241
Set CSVix = Nothing 'Terminate the current instance
177242
End Sub
178243
```

0 commit comments

Comments
 (0)