Skip to content

Commit ae8c5a5

Browse files
authored
Bug fixes
Fixed bugs in the GetDataFromCSV method
1 parent f2ec057 commit ae8c5a5

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/CSVinterface.cls

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,14 @@ End Sub
326326
Public Function GetDataFromCSV(csvPathAndFilename As String) As String
327327
'////////////////////////////////////////////////////////////////////////////////////////////
328328
' DESCRIPTION:
329-
' This method read CSV content and pass it to OutPutVar variable. This is not elegant but,
330-
' the purpose is the avoid execution speed losses. To use this method, first, you need to
331-
' open a connection ussing the OpenConnection method, to point to the CSV file.
329+
' This method read CSV content and returns a string variable. To use this method, you need
330+
' to specify a path to point to the CSV file.
332331
'////////////////////////////////////////////////////////////////////////////////////////////
333332
Dim tmpStr As String
334333

335334
On Error Resume Next
336-
tmpStr = Space$(LOF(FileHandled))
335+
Call OpenConnection(csvPathAndFilename)
336+
tmpStr = Space$(FileLen(csvPathAndFilename))
337337
Get #FileHandled, , tmpStr
338338
GetDataFromCSV = tmpStr
339339
Call CloseConnection
@@ -672,15 +672,21 @@ Public Function RemoveSpaces(ByRef CSVrecords As String) As String
672672
With RegEx
673673
'@----------------------------------------------------------------------------
674674
'Remove spaces from fields
675-
strPattern = EscapeChar & "\s*" & P_FIELDS_DELIMITER & "\s*" & EscapeChar
675+
strPattern = EscapeChar & "\s*" & P_FIELDS_DELIMITER
676676
.Pattern = strPattern
677677
.Global = True
678-
tmpStr = .Replace(CSVrecords, EscapeChar & P_FIELDS_DELIMITER & EscapeChar)
678+
tmpStr = .Replace(CSVrecords, EscapeChar & P_FIELDS_DELIMITER)
679+
strPattern = P_FIELDS_DELIMITER & "\s*" & EscapeChar
680+
.Pattern = strPattern
681+
tmpStr = .Replace(tmpStr, P_FIELDS_DELIMITER & EscapeChar)
679682
'@----------------------------------------------------------------------------
680683
'Remove spaces from records
681-
strPattern = EscapeChar & "\s*" & P_RECORDS_DELIMITER & "\s*" & EscapeChar
684+
strPattern = EscapeChar & "\s*" & P_RECORDS_DELIMITER
685+
.Pattern = strPattern
686+
tmpStr = .Replace(tmpStr, EscapeChar & P_RECORDS_DELIMITER)
687+
strPattern = P_RECORDS_DELIMITER & "\s*" & EscapeChar
682688
.Pattern = strPattern
683-
RemoveSpaces = .Replace(tmpStr, EscapeChar & P_RECORDS_DELIMITER & EscapeChar)
689+
RemoveSpaces = .Replace(tmpStr, P_RECORDS_DELIMITER & EscapeChar)
684690
End With
685691
End Function
686692
Public Sub ResetToDefault()

0 commit comments

Comments
 (0)