Solved

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

Posted on 2003-10-23
10
366 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:JMCrenshaw
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 1

Expert Comment

by:TwistD_PissR
ID: 9608527
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
0
 

Author Comment

by:JMCrenshaw
ID: 9608568
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.

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9609122
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.

0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 9611601
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
0
 
LVL 4

Accepted Solution

by:
TigerZhao earned 125 total points
ID: 9611747
Another solution, not use PUBLIC UDT
1.Collection Class, Name = "CData", Instancing = 5 - MultiUse
    Option Explicit
   
    Private Type outlays
        Loan As Double
        Withdrawl As Single
    End Type
   
    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
   
        Set outlays = New COutlays
        outlays.Bind Me, Index
    End Property
   
    Friend Property Get Loan(ByVal Index As Long) As Double
        Loan = myVar(Index).Loan
    End Property
    Friend Property Let Loan(ByVal Index As Long, ByVal RHS As Double)
        myVar(Index).Loan = RHS
    End Property
   
    Friend Property Get Withdrawl(ByVal Index As Long) As Double
        Withdrawl = myVar(Index).Withdrawl
    End Property
    Friend Property Let Withdrawl(ByVal Index As Long, ByVal RHS As Double)
        myVar(Index).Withdrawl = RHS
    End Property
2.Data item access class, Name = "COutlays", Instancing = 2 - PublicNotCreatable
    Option Explicit
    Private mData As CData
    Private mIndex As Long
   
    Friend Sub Bind(ByVal Data As CData, ByVal Index As Long)
        Set mData = Data
        mIndex = Index
    End Sub
   
    Public Property Get Loan() As Double
        Loan = mData.Loan(mIndex)
    End Property
    Public Property Let Loan(ByVal RHS As Double)
        mData.Loan(mIndex) = RHS
    End Property
   
    Public Property Get Withdrawl() As Double
        Withdrawl = mData.Withdrawl(mIndex)
    End Property
    Public Property Let Withdrawl(ByVal RHS As Double)
        mData.Withdrawl(mIndex) = RHS
    End Property
3.test code
    Dim clsInput As CData
    Dim x As Long
    x = 100
   
    Set clsInput = New CData
    clsInput.outlays(x).Loan = 1500#
    clsInput.outlays(x).Withdrawl = 200#
   
    Debug.Print clsInput.outlays(x).Loan, clsInput.outlays(x).Withdrawl
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 26

Expert Comment

by:EDDYKT
ID: 9613534
0
 

Author Comment

by:JMCrenshaw
ID: 9614579
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.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9614900
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?
0
 

Author Comment

by:JMCrenshaw
ID: 9615148
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

0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9615215
Thanks to God!, i have been starting to think that i have losing my skills.
;)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now