Solved

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

Posted on 2003-10-23
10
382 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 73
Sending a email via excel using vba 6 95
Advice in Xamarin 21 95
VB6 common control 6 sp6 object library not registerd 3 19
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

789 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