1

I've been working on this and researching for hours with no luck. I'm coming from a Java background and working in VBA again, so building class modules is probably not best practice, but I'm doing it anyway and I'm paying for it. Here's the story:

I've built 2 class modules: PermissionFile and PermissionState. The state is a glorified variant array. Here's the relevant code

Private permissionArray() As Variant

Sub Initialize(Optional file As PermissionFile)
    ReDim permissionArray(6808, 1)
End Sub

Function getPermission(rowNumber, index)
    getValue = permissionArray(rowNumber, index)
End Function

no real problems there that I can see.

PermissionFile does all the heavy parsing. As mentioned, it contains a PermissionState called 'state', and it builds just fine. Here's the relevant code on that:

Private state As PermissionState    'this is declared outside of the sub, 
                                    'so scope is global

Sub Initialize(filePath As String)
    Set state = New PermissionState
    state.Initialize
End Sub

'here are the two different getter functions I've tried. They aren't
'both on at the same time, just different things I've tried

Public Property Get getState() As PermissionState
    getState = state
End Property

Function getState()
    getState = state
End Function

and finally, here's the call from the client

'new permission file
Dim permFile2 As PermissionFile
Set permFile2 = New PermissionFile
permFile2.Initialize (path2)

'new permission state
Dim myState As PermissionState
Set myState = New PermissionState

'set new state as state from file
myState = permFile2.getState()

Everything builds just fine - my instances are all there as the correct data types, each File has a State with an array with all the data, and everything looks like it should be working; but when it calls 'getState', I get an "Run-time error '91: Object variable or With block variable not set" error.

I'm totally stumped, and it's probably a really simple step, but it's killing my productivity, so any help would be greatly, greatly appreciated. I can put up more of the code if it helps.

1 Answer 1

0

The value of a primitive data type variables can get set with just an equal sign. Object variables require you to use the Set keyword.

Add Set to both the function return Set getState = state and where you store the state in your regular module function Set myState = permFile2.getState().

1
  • That was it, thank you so much! I knew it had to be something simple like that, and so it was. Greatly appreciated Aug 5, 2015 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.