Skip to content

Commit

Permalink
Now compiles on 32bit Excel
Browse files Browse the repository at this point in the history
  • Loading branch information
PGS62 committed Sep 1, 2021
1 parent 1c444d1 commit c30d89a
Show file tree
Hide file tree
Showing 11 changed files with 4,772 additions and 1,617 deletions.
2 changes: 1 addition & 1 deletion dev/modCSVDevUtils.bas
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Sub SaveWorkbookAndExportModules()
End Select

'only export files of the PGS62 project, not those from other _
CSV parsers that I have imported to compare performance.
CSV parsers that I have imported to compare performance.
If Left(FileName, 6) <> "modCSV" Then
bExport = False
End If
Expand Down
9 changes: 1 addition & 8 deletions dev/modCSVPerformance.bas
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ ErrHandler:
TimeFourParsers = "#TimeFourParsers (line " & CStr(Erl) + "): " & Err.Description & "!"
End Function


Sub AddCharts(Optional Export As Boolean = True)

Dim c As ChartObject
Expand Down Expand Up @@ -326,7 +325,6 @@ ErrHandler:
MsgBox "#AddCharts (line " & CStr(Erl) + "): " & Err.Description & "!"
End Sub


Sub AddChartAtSelection()
On Error GoTo ErrHandler

Expand Down Expand Up @@ -378,8 +376,7 @@ Sub AddChart(Optional xData As Range, Optional yData As Range, Optional Export A
wsh.Activate
Range(xData.Address & "," & yData.Address).Select
End If



Set shp = wsh.Shapes.AddChart2(240, xlXYScatterLines)
Set ch = shp.Chart
ch.SetSourceData Source:=Application.Union(xData, yData)
Expand Down Expand Up @@ -417,7 +414,3 @@ Sub AddChart(Optional xData As Range, Optional yData As Range, Optional Export A
ErrHandler:
Throw "#AddChart (line " & CStr(Erl) + "): " & Err.Description & "!"
End Sub




5,991 changes: 4,493 additions & 1,498 deletions dev/modCSVTest.bas

Large diffs are not rendered by default.

118 changes: 63 additions & 55 deletions dev/modCSVTestDeps.bas
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Attribute VB_Name = "modCSVTestDeps"
' Document: https://github.com/PGS62/VBA-CSV#readme

'This module contains "test dependencies" of CSVReadWrite, i.e. dependencies of the code used to test ModCSVReadWrite, _
but not dependencies of ModCSVReadWrite itself which is (should be) self-contained
but not dependencies of ModCSVReadWrite itself which is (should be) self-contained

Option Explicit
Option Private Module

#If VBA7 Then
#If VBA7 And Win64 Then
Private Declare PtrSafe Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Private Declare PtrSafe Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
#Else
Expand All @@ -26,14 +26,14 @@ Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCo
' identical to Expected. If not sets WhatDiffers to a description of what went wrong.
' -----------------------------------------------------------------------------------------------------------------------
Function TestCSVRead(CaseNo As Long, ByVal TestDescription As String, Expected As Variant, FileName As String, ByRef Observed, _
ByRef WhatDiffers As String, Optional AbsTol As Double, Optional RelTol As Double, Optional ConvertTypes As Variant = False, _
Optional ByVal Delimiter As Variant, Optional IgnoreRepeated As Boolean, _
Optional DateFormat As String, Optional Comment As String, Optional IgnoreEmptyLines As Boolean = True, Optional ByVal SkipToRow As Long = 1, _
Optional ByVal SkipToCol As Long = 1, Optional ByVal NumRows As Long = 0, _
Optional ByVal NumCols As Long = 0, Optional HeaderRowNum As Long, Optional TrueStrings As Variant, Optional FalseStrings As Variant, _
Optional MissingStrings As Variant, Optional ByVal ShowMissingsAs As Variant = "", _
Optional ByVal Encoding As Variant, Optional DecimalSeparator As String = vbNullString, _
Optional NumRowsExpected As Long, Optional NumColsExpected As Long, Optional ByRef HeaderRow, Optional ExpectedHeaderRow) As Boolean
ByRef WhatDiffers As String, Optional AbsTol As Double, Optional RelTol As Double, Optional ConvertTypes As Variant = False, _
Optional ByVal Delimiter As Variant, Optional IgnoreRepeated As Boolean, _
Optional DateFormat As String, Optional Comment As String, Optional IgnoreEmptyLines As Boolean = True, Optional ByVal SkipToRow As Long = 1, _
Optional ByVal SkipToCol As Long = 1, Optional ByVal NumRows As Long = 0, _
Optional ByVal NumCols As Long = 0, Optional HeaderRowNum As Long, Optional TrueStrings As Variant, Optional FalseStrings As Variant, _
Optional MissingStrings As Variant, Optional ByVal ShowMissingsAs As Variant = "", _
Optional ByVal Encoding As Variant, Optional DecimalSeparator As String = vbNullString, _
Optional NumRowsExpected As Long, Optional NumColsExpected As Long, Optional ByRef HeaderRow, Optional ExpectedHeaderRow) As Boolean

On Error GoTo ErrHandler

Expand Down Expand Up @@ -67,6 +67,15 @@ Function TestCSVRead(CaseNo As Long, ByVal TestDescription As String, Expected A
If Observed = Expected Then
TestCSVRead = True
Exit Function
ElseIf RegExSyntaxValid(CStr(Expected)) Then
If IsRegMatch(CStr(Expected), CStr(Observed)) Then
TestCSVRead = True
Exit Function
Else
WhatDiffers = TestDescription + " FAILED, CSVRead returned error: '" + Observed + _
"' but expected a different error: '" + Expected + "'"
GoTo Failed
End If
Else
WhatDiffers = TestDescription + " FAILED, CSVRead returned error: '" + Observed + _
"' but expected a different error: '" + Expected + "'"
Expand Down Expand Up @@ -105,6 +114,48 @@ Function NameThatFile(Folder As String, ByVal OS As String, NumRows As Long, Num
NameThatFile = (Folder & "\" & IIf(ExtraInfo = "", "", ExtraInfo & "_") & IIf(OS = "", "", OS & "_") & Format(NumRows, "0000") & "_x_" & Format(NumCols, "000") & IIf(Unicode, "_Unicode", "_Ascii") & IIf(Ragged, "_Ragged", "") & ".csv")
End Function

'---------------------------------------------------------------------------------------
' Procedure : sNCols
' Purpose : Number of columns in an array. Missing has zero rows, 1-dimensional arrays
' have one row and the number of columns returned by this function.
'---------------------------------------------------------------------------------------
Function sNCols(Optional TheArray) As Long
If TypeName(TheArray) = "Range" Then
sNCols = TheArray.Columns.Count
ElseIf IsMissing(TheArray) Then
sNCols = 0
ElseIf VarType(TheArray) < vbArray Then
sNCols = 1
Else
Select Case NumDimensions(TheArray)
Case 1
sNCols = UBound(TheArray, 1) - LBound(TheArray, 1) + 1
Case Else
sNCols = UBound(TheArray, 2) - LBound(TheArray, 2) + 1
End Select
End If
End Function
'---------------------------------------------------------------------------------------
' Procedure : sNRows
' Purpose : Number of rows in an array. Missing has zero rows, 1-dimensional arrays have one row.
'---------------------------------------------------------------------------------------
Function sNRows(Optional TheArray) As Long
If TypeName(TheArray) = "Range" Then
sNRows = TheArray.Rows.Count
ElseIf IsMissing(TheArray) Then
sNRows = 0
ElseIf VarType(TheArray) < vbArray Then
sNRows = 1
Else
Select Case NumDimensions(TheArray)
Case 1
sNRows = 1
Case Else
sNRows = UBound(TheArray, 1) - LBound(TheArray, 1) + 1
End Select
End If
End Function

'---------------------------------------------------------------------------------------------------------
' Procedure : CreatePath
' Purpose : Creates a folder on disk. FolderPath can be passed in as C:\This\That\TheOther even if the
Expand Down Expand Up @@ -212,28 +263,6 @@ ErrHandler:
Throw "#sElapsedTime: " & Err.Description & "!"
End Function

'---------------------------------------------------------------------------------------
' Procedure : sNCols
' Purpose : Number of columns in an array. Missing has zero rows, 1-dimensional arrays
' have one row and the number of columns returned by this function.
'---------------------------------------------------------------------------------------
Function sNCols(Optional TheArray) As Long
If TypeName(TheArray) = "Range" Then
sNCols = TheArray.Columns.Count
ElseIf IsMissing(TheArray) Then
sNCols = 0
ElseIf VarType(TheArray) < vbArray Then
sNCols = 1
Else
Select Case NumDimensions(TheArray)
Case 1
sNCols = UBound(TheArray, 1) - LBound(TheArray, 1) + 1
Case Else
sNCols = UBound(TheArray, 2) - LBound(TheArray, 2) + 1
End Select
End If
End Function

'Copy of identical function in modCVSReadWrite
Function NumDimensions(x As Variant) As Long
Dim i As Long
Expand All @@ -253,27 +282,6 @@ ExitPoint:
NumDimensions = i - 1
End Function

'---------------------------------------------------------------------------------------
' Procedure : sNRows
' Purpose : Number of rows in an array. Missing has zero rows, 1-dimensional arrays have one row.
'---------------------------------------------------------------------------------------
Function sNRows(Optional TheArray) As Long
If TypeName(TheArray) = "Range" Then
sNRows = TheArray.Rows.Count
ElseIf IsMissing(TheArray) Then
sNRows = 0
ElseIf VarType(TheArray) < vbArray Then
sNRows = 1
Else
Select Case NumDimensions(TheArray)
Case 1
sNRows = 1
Case Else
sNRows = UBound(TheArray, 1) - LBound(TheArray, 1) + 1
End Select
End If
End Function

' -----------------------------------------------------------------------------------------------------------------------
' Procedure : Throw
' Purpose : Simple error handling.
Expand Down Expand Up @@ -740,8 +748,8 @@ End Function
' AbsTol,RelTol : Tolerances for inexact equality comparison. See sIsApprox.
' -----------------------------------------------------------------------------------------------------------------------
Function sArraysIdentical(ByVal Array1, ByVal Array2, Optional CaseSensitive As Boolean, _
Optional PermitBaseDifference As Boolean = False, Optional ByRef WhatDiffers As String, _
Optional AbsTol As Double, Optional RelTol As Double) As Variant
Optional PermitBaseDifference As Boolean = False, Optional ByRef WhatDiffers As String, _
Optional AbsTol As Double, Optional RelTol As Double) As Variant

Dim cN As Long
Dim i As Long
Expand Down
7 changes: 3 additions & 4 deletions dev/modCSVTestRoundTrip.bas
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ Private Sub RoundTripTestCore(Folder As String, OS As String, ByVal Data As Vari
NumFailed = NumFailed + 1
End If

NumDone = NumPassed + NumFailed
If NumDone Mod 50 = 0 Then Debug.Print Format(NumDone, "###,##0")


NumDone = NumPassed + NumFailed
If NumDone Mod 50 = 0 Then Debug.Print Format(NumDone, "###,##0")

Exit Sub
ErrHandler:
Throw "#RoundTripTestCore: " & Err.Description & "!"
Expand Down
39 changes: 22 additions & 17 deletions dev/modCSVTestUtils.bas
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,30 @@ Function GenerateTestCode(CaseNo As Long, FileName, ExpectedReturn As Variant, C

Dim Res As String
Dim LitteralExpected
Dim ExpectedInSepFn As Boolean

Const IndentBy = 4

On Error GoTo ErrHandler

Res = "Case " & CStr(CaseNo) & vbLf & _
"TestDescription = """ & Replace(Replace(FileName, "_", " "), ".csv", "") & """" & vbLf & _
"FileName = """ & FileName & """" & vbLf
Res = "Sub Case" & CaseNo & "(i As Long, Folder As String, ByRef NumPassed As Long, ByRef NumFailed As Long, ByRef Failures() As String)"
Res = Res & vbLf & " Dim TestDescription As String, FileName As String, Expected, Observed, TestRes As Variant, WhatDiffers As String"
Res = Res & vbLf
Res = Res & vbLf & "On Error GoTo ErrHandler"

Res = Res & vbLf & _
"TestDescription = """ & Replace(Replace(FileName, "_", " "), ".csv", "") & """"

If Not IsArray(ExpectedReturn) Then
LitteralExpected = ElementToVBALitteral(ExpectedReturn)
Else
LitteralExpected = ArrayToVBALitteral(ExpectedReturn, , 120)
If Left(LitteralExpected, 1) = "#" Then
ExpectedInSepFn = True
End If
End If

If Not ExpectedInSepFn Then
Res = Res & "Expected = " & LitteralExpected
Else
ExpectedInSepFn = True
Res = Res & "Expected = Expected" + Format(CaseNo, "000") + "()"
End If
Res = Res + vbLf + "Expected = " & LitteralExpected

Res = Res + vbLf + "FileName = """ & FileName & """"

If Left(FileName, 4) = "http" Then
Res = Res + vbLf + "TestRes = TestCSVRead(i, TestDescription, Expected, FileName, Observed, WhatDiffers"
Expand Down Expand Up @@ -126,12 +125,18 @@ Function GenerateTestCode(CaseNo As Long, FileName, ExpectedReturn As Variant, C

Res = Res + ")"

If ExpectedInSepFn Then
Res = Res + vbLf + vbLf + vbLf + _
"Function Expected" & Format(CaseNo, "000") & "()" + vbLf + _
ArrayToVBALitteral(ExpectedReturn, "Expected" & Format(CaseNo, "000"), 10000) + vbLf + _
"End Function"
End If
Res = Res & vbLf & " If TestRes Then"
Res = Res & vbLf & " NumPassed = NumPassed + 1"
Res = Res & vbLf & " Else"
Res = Res & vbLf & " NumFailed = NumFailed + 1"
Res = Res & vbLf & " ReDim Preserve Failures(LBound(Failures) To UBound(Failures) + 1)"
Res = Res & vbLf & " Failures(UBound(Failures)) = WhatDiffers"
Res = Res & vbLf & " End If"
Res = Res & vbLf & ""
Res = Res & vbLf & " Exit Sub"
Res = Res & vbLf & "ErrHandler:"
Res = Res & vbLf & " Throw ""#Case3 (line "" & CStr(Erl) + ""): "" & Err.Description & ""!"""
Res = Res & vbLf & "End Sub"

GenerateTestCode = Transpose(Split(Res, vbLf))

Expand Down
9 changes: 4 additions & 5 deletions dev/modCSVXLUtils.bas
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ Attribute VB_Name = "modCSVXLUtils"

Option Explicit
'Functions that, in addition to CSVRead and CSVWrite, are called from the worksheets of this workbook _
see also mod
see also mod

Function TempFolder()
TempFolder = Environ("Temp")
End Function

Function TestFolder()
TestFolder = Left(ThisWorkbook.path, InStrRev(ThisWorkbook.path, "\")) + "testfiles\"
TestFolder = Left(ThisWorkbook.path, InStrRev(ThisWorkbook.path, "\")) + "testfiles\"
End Function


'---------------------------------------------------------------------------------------------------------
' Procedure : ArrayEquals
' Purpose : Element-wise testing for equality of two arrays - the array version of sEquals. Like the =
Expand Down Expand Up @@ -305,7 +304,7 @@ End Function
' of those elements concatenated with given delimiter.
' -----------------------------------------------------------------------------------------------------------------------
Function AllCombinations(Arg1, Optional Arg2, Optional Arg3, _
Optional Arg4, Optional Delimiter As String)
Optional Arg4, Optional Delimiter As String)
Dim Res() As String
Dim Part1 As Variant
Dim Part2 As Variant
Expand Down Expand Up @@ -523,7 +522,7 @@ End Function
' Procedure : RegExSyntaxValid
' Purpose : Tests syntax of a regular expression.
' -----------------------------------------------------------------------------------------------------------------------
Private Function RegExSyntaxValid(RegularExpression As String) As Boolean
Function RegExSyntaxValid(RegularExpression As String) As Boolean
Dim Res As Boolean
Dim rx As VBScript_RegExp_55.RegExp
On Error GoTo ErrHandler
Expand Down
Loading

0 comments on commit c30d89a

Please sign in to comment.