0

I have the following code:

Private Enum dbi
        m = 0
        d = 1
        y = 2
        hh = 3
        mm = 4
        ss = 5
        ap = 6
        size = 7
End Enum

...

Sub CompileData()

    ...

    ReDim startEnd(deplCount * 2) As Date
    ReDim excludes(deplCount * 2) As Date
    ReDim hasExcls(deplCount) As Boolean

    ReDim deplLabels(deplCount) As MSForms.Label
    ReDim startLabels(deplCount) As MSForms.Label
    ReDim endLabels(deplCount) As MSForms.Label
    ReDim exclLabels(deplCount) As MSForms.Label
    ReDim exclChecks(deplCount) As MSForms.CheckBox

    ReDim mdyLabels(dbi.size * 2 * deplCount) As MSForms.Label

    ReDim dateGroup(dbi.size * 4 * deplCount) As MSForms.TextBox
    ReDim pctLabels(dbi.size * 4 * deplCount) As MSForms.Label

    Dim okButton As MSForms.CommandButton

    ...

End Sub

Note these two chunks lie in the same module, so even though the Enum is private, CompileData should still be able to access it.

I am ReDimming some arrays because I am not sure before the program launches how much data I am going to need to collect from this userform. This code has worked for a month, but now for some reason I am getting a constant expression compile error in the CompileData sub that specifically highlights "dbi.size." Are Enums suddenly not considered constant definitions? If I'm ReDimming, should it even matter?

  • 1
    [This old question](https://stackoverflow.com/q/13196909/2127508) suggests that this can be an intermittent error and that changing the enum to `Public Enum` or to just `Enum` can sometimes help – barrowc Nov 22 '19 at 19:05
  • @barrowc Yep, after doing a little more experimenting that seems to be my issue as well. I guess I can remove the question as a duplicate? – Edward Casey Nov 22 '19 at 19:19
  • I've voted to close this as a duplicate. There's no need to delete the question. If it gets a few more duplicate votes then it will be automatically put on hold anyway – barrowc Nov 22 '19 at 19:24
  • 1
    FWIW the linked OP mentions randomness as they haven't experienced the issue with or without a `Public` keyword - they seem to have missed the fact that `Public` is the implicit default in VBA. Also yes, `Enum` types are buggy in ways you can't even imagine, I have stories... – Mathieu Guindon Nov 22 '19 at 19:25

1 Answers1

0

After tooling around it appeared that all references to the Enum weren't working. I took off the "Private" handle and that has fixed the issue.