Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2003-10-23
10
Medium Priority
?
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 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