I want to use a Dictionary as a private variable in a module. I tried the following code, but the vba editor marks the collection (variable resource) red when I want to access it in a procedure. How do I have to code this?
Option Explicit
Private Type Translation
german As String
french As String
italian As String
End Type
Private resource
Set resource = CreateObject("scripting.dictionary")
Public Sub addTranslation(key As String, g As String, f As String, i As String)
Dim trx As Translation
trx.german = g
trx.french = f
trx.italian = i
resource.add(key, trx) '<== marked red
End Sub
'more methods to come which do access resource
The instancing:
Needs to be in a sub/function not in the declaration, you can add it somewhere convenient or change the declaration to:
and add a guard check whenever you access it (instancing it once elsewhere is obviously better);
And no parens in the
.addcall so: