我对VBA并不陌生,但我不熟悉课程,而且我现在正在努力修改一些词典。 这是我班级的缩减版本:
Option Explicit
'Variables required for object operations
Private pFilePath As String 'contains the file path of the TAB file.
...
Private pDATAFields As Object 'dictionary1
Private pMetadata As Object 'dictionary2
Private Sub Class_Initialize()
Set pDATAFields = CreateObject("Scripting.Dictionary")
Set pMetadata = CreateObject("Scripting.Dictionary")
End Sub
...
Public Property Get DATAFields() As Object
DATAFields = pDATAFields
End Property
Public Property Get Metadata() As Object
Metadata = pMetadata
End Property
'Methods required
Public Sub initialise(sFilePath As String)
'sTABText contains the text from file at sFilePath
Dim sTabText As String
sTabText = harvestTextFile(sFilePath)
...
pTABVersion = pullPart("Version", strArr(1), 1)
...
Set pDATAFields = generateFieldStructureDict(strArr, 6, 5 + pDATAFieldNumber)
...
'Generate the metadata dictionary from the file
Set pMetadata = generateMetadataDict(strArr, i + 1)
End Sub
Private Function generateFieldStructureDict(arg1 as string, arg2 as integer, arg3 as Integer) as Object
Dim oObj as Object
Set oObj = CreateObject("scripting.dictionary")
... do stuff
Set generateFieldStructureDict = oObj
End Function
... Similar function for generateMetadataDict
根据我自己的观察,这应该有效,但由于某种原因,它并不适用。诸如pTABVersion
之类的属性设置得很好。它似乎只是pDATAFields
和pMetadata
未正确设置。
如果我一步一步地遵循函数generateFieldStructureDict
,我会在函数结束时看到:
set generateFieldStructureDict = oObj
这部分工作得非常好。 oObj
中的字典会传递到generateFieldStructureDict
。然而,当我们返回初始化子例程时:
Set pDATAFields = generateFieldStructureDict(strArr, 6, 5 + pDATAFieldNumber)
generateFieldStructureDict
似乎丢失了我提供的所有数据。最终clsTab.filePath
和clsTab.tabVersion
将返回pFilePath
和pTabVersion
(因为它们已设置)。但是clsTab.DATAFields
和clsTab.Metadata
不会像他们应该的那样返回字典。这是因为pMetadata
和pDATAFields
由于某种原因未设置。
有没有人对我需要做些什么来实现这项工作?