Link to home
Start Free TrialLog in
Avatar of JMCrenshaw
JMCrenshaw

asked on

Passing UDT's or Arrays to a class module in activex dll

I have a large application in VB 6 that uses collections to handle passing data from an input program to an activex dll.  For example the collection contains 4 different Propertys defined as doubles or singles.

When I intialize the class I automatcily add 120 items so that the user can pass their data from an array or grid to the dll. IE:

The user addresses the collection as follows
 input.outlays(x).Loans = 1500.00
 input.outlays(x).Withdrawls = 200.00

The problem is the large time and overhead it takes to create the collection with 120 items at the Class initalization. What I want to do is convert this to use a UDT of arrays ie:

Type Outlays
    Loan as Double
   Withdrawl as Single
end type

Public myVar as Outlays(120)

I would like for the user to be able to use the same syntax as above to set the values if possible and if not possible how would you accomplish this.

John C
Avatar of TwistD_PissR
TwistD_PissR

If I understand your question correctly, you are trying to just make the collection from the ActiveX dll sizable based on user input....

If so do you have any size limitations on the collection within the activex dll?

What you could do is generate a file (.ini, txt) that the application wil use to set and get the size of the collection that the user wants or use the SaveSetting and GetSetting functions from within VB (which writes it to the registry).

TwistD
Avatar of JMCrenshaw

ASKER

No I want to get rid of the Collection approach because of the performance issues with large collections.

I would rather use a  User Defined Type (UDT) that is arrayed with 120 elements (see code in the question).  My question is how can I convert this to use the UDT's instead of the collection with out forcing the client to make dramatic changes in passing the data.

Avatar of Richie_Simonetti
If i understood:
'in your class
public Type Outlays
    Loan as Double
   Withdrawl as Single
end type

' you could do this:
Public myVar as Outlays(120)

'or, create a property of type Outlays, i think.

To JMCrenshaw:
If you has follow property in ypu class
  Public Property Get outlays(Byval Index As Long) AS Outlays
      outlays = myVar(Index)
  End Property
  Public Property Let outlays(Byval Index As Long, RHS As Outlays)
      myVar(Index) = RHS
  End Property
you still can't use follow code to modify data in class, because you access Propety Get, and modify UDT's value return by Property Get (It's alawys copy UDT data, not reference original UDT)
  input.outlays(x).Loans = 1500.00
  input.outlays(x).Withdrawls = 200.00
suggest you add another
  Public Sub SetOutlaysVal(ByVal Index As Long, Byval Loans As Double, Byval Withdrawls As Single)
      With myVar(Index)
          .Loans = Loans
          .Withdrawls = Withdrawls
      End With
  End Sub
and change call code to
  input.SetOutlaysVal x, 1500.00, 200.00
ASKER CERTIFIED SOLUTION
Avatar of TigerZhao
TigerZhao

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
TigerZhao

Thanks for the complete example.  Your Example in Cdata for the property let and get was what I needed to see to bring it all into focus.
Sorry for ask but:

Private myVar(120) As outlays
   
    Public Property Get outlays(ByVal Index As Long) As COutlays
        If (Index < 1) Or (120 < Index) Then Err.Raise 9 'Subscript out of range

variable array declared myVar(120) means 0 to 120 and not 1 to 120 at least, if you don't use option base 1 so the test :  If (Index < 1) would fails when indes is 0
or am i wrong?
Richie

You are correct in my case I do not use Option Base 1 and the code would need to be adjusted to

If (Index < 120) And ( Index > -1 ) =  false then Err.Raise 9 ''Subscript out of range

Thanks to God!, i have been starting to think that i have losing my skills.
;)