ActiveX Form problems...
Posted on 2004-11-05
I am working on an activex form in VB6 and have run up against a problem that I am certain is due to my lack of understanding of how classes work. The form is called from a class (clsMain) with this function:
Public Function get_form(filename As String, vData As Variant) As Variant
Dim frm As frmMain
varData = vData
Set frm = New frmMain
get_form = varReturn
Set frm = Nothing
The form (frmMain) is made up of listboxes that are filled from a database. In order to simplify the setting and returning of different configurations of selected values in these listboxes I have added another class named clsSettings. The object that instantiates the class holds the listboxes’ current values as a variant which is set/updated by a method (named Update). In order to get the current values – I iterate through the form’s controls
For Each ctl In frmMain.Controls
[if listbox then get current value and add to array]
then I set a public property in the clsSettings to the result.
This works as expected when I run the program from VB or as a compiled exe. I can change the values in the lists and each time I test the Update method of the clsSettings object, the new values are returned. However, when I invoke the dll with get_form (from clsMain) then the object only returns the values that were set when the form (frmMain) was originally called. The Update function iterates through the controls as expected but doesn’t recognize that the listbox values have changed.
Have I explained this well enough for anyone to see my error? If I can’t manage to save/put the settings with a class, then I guess that I will need to move all of the code/variables from the clsSettings directly into the frmMain code (which will be simple enough). It seems to me, though that the approach that I am taking now is the better one and certainly will be simpler to maintain – so I’ll hope for some advice/insights from the experts in this forum.
Thanks in advance,