I am creating a class module with a private Dictionary in VB6. I successfully insert and retrieve Strings, Integers, Dates, and RecordSets (into/from the Dictionary). I have successfully written functions to retrieve and return the Strings, Integers, and Dates, but I am having difficulty with the RecordSets. If I make the dictionary public, I can see/retrieve the RecordSet with no problem. But I would prefer to keep the Dictionary private and use a function (many reasons).
Here is the code that uses the class module:
Dim myobject As New MyClassModule
myobject.AddToDictionary 'adds the RecordSet (code below)
Set myMSHFlexGrid.DataSource = myobject.d.Item("mykey") 'works fine
'Set myMSHFlexGrid.DataSource = myobject.getRS("mykey") 'no workey!
'MyClassModule below including 2 attempts at get/return
Public d As New Dictionary 'wish it were private ;(
Public Sub AddToDictionary() 'create and add a RecordSet to the Dictionary
Dim rs As New Recordset
rs.Fields.Append "Field1", adBSTR
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.Fields.Item(0) = "test1"
d.Add key:="mykey", Item:=rs
Public Function getRS(key As String) As Recordset 'error: invalid use of property
tget = d.Item(key)
Public Function getRS(key As String) As Object
tget = d.Item(key) 'error: object variable or with block variable not set
By the way, VarType(d.Item(key)) returns vbObject! Is there a downcast in VB6?
I have almost identical code working for the Dates, Strings, and Integers
Thanks for any help, much obliged-