HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Data Table Report Class

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
reportdataclasstable

Problem

Most of the VBA I write is to produce tabulated reports from spreadsheet data.

So, here is my attempt at creating a CLS_Data_Report class.

Properties:

a 2-dimensional Data Array

3 dictionaries to, respectively:

-
Map headers to column indexes

-
Map external (user-set) descriptions to data headers

-
Store number formatting for columns (by header)

And the PrintRange (for other visual formatting, e.g. row-colouring)

Key Methods:

-
Add Data to the Array (options for merging, overwriting, replacing)

-
Create a filtered report based on a single columns' values

-
Print the report to a worksheet (and set number formatting)

What I would especially like to know is, is this a good abstraction? (Is it too high, not high enough, is it trying to do too much, not enough?)

As always, any other feedback is greatly appreciated.

Properties and Class_Initialize

Option Explicit

Private pReportData As Variant '/ Data Array

Private pMapDescriptionsToHeaders As Scripting.Dictionary
Private pColumnIndexesOfHeaders As Scripting.Dictionary
Private pNumberFormatsOfHeaderColumns As Scripting.Dictionary

Private pPrintRange As Range

'/============================================================================================================================================================
Private Sub Class_Initialize()

    pReportData = Array()
    
    Set pMapDescriptionsToHeaders = New Scripting.Dictionary
    Set pNumberFormatsOfHeaderColumns = New Scripting.Dictionary
    Set pColumnIndexesOfHeaders = New Scripting.Dictionary
    
End Sub


Property Get/Set

```
'/============================================================================================================================================================
Public Property Get printRange() As Range
Set printRange = pPrintRange
End Property
Public Property Set printRange(ByRef printRange As Range)
Set pPrintRange = printRange
End Property

'/===========================================

Solution

Just a quick shot at

Public Property Get MapDescriptionsToHeaders() As Scripting.Dictionary
    Set MapDescriptionsToHeaders = pMapDescriptionsToHeaders
End Property
Public Property Set MapDescriptionsToHeaders(ByRef descriptions As Scripting.Dictionary)
    Set pMapDescriptionsToHeaders = MapDescriptionsToHeaders
End Property


you aren't assigning the descriptions As Scripting.Dictionary but you are calling the getter out of the setter which seems to be some copy&pasta bug.

Code Snippets

Public Property Get MapDescriptionsToHeaders() As Scripting.Dictionary
    Set MapDescriptionsToHeaders = pMapDescriptionsToHeaders
End Property
Public Property Set MapDescriptionsToHeaders(ByRef descriptions As Scripting.Dictionary)
    Set pMapDescriptionsToHeaders = MapDescriptionsToHeaders
End Property

Context

StackExchange Code Review Q#118525, answer score: 5

Revisions (0)

No revisions yet.