Solved

Setting linked parameters/properties in a VBA class

Posted on 2012-03-18
3
186 Views
Last Modified: 2012-03-20
I am developing a set of class modules in VBA for Excel.  One class, representing a Process Unit in an industrial plant, has to hold information about its linkages to other instances of the same class.  I am able to build an array in one unit that holds the linked units but I now want to associate a numerical value with each linkage.

My question is how can I do this cleanly.  Ideally I would do it when setting the link but at the moment all I seem to be able to do is pass the identity of the other process unit rather than its identity and the associated value at the same time.

The relevant bits of the class code are as follows where iPrerequisiteDelay is the value I want to associate with the link

Dim Prerequisite() As clsProcessUnit, iPrerequisiteDelay() As Integer
Private piPrerequisites As Integer, piInterruptions As Integer, piLoop As Integer


...

Public Property Let Requires(Unit As clsProcessUnit)

'   Create a link from this unit to a unit it needs to be Up for this one to operate

    piPrerequisites = piPrerequisites + 1
    ReDim Prerequisite(piPrerequisites)
'    ReDim iPrerequisiteDelay(piPrerequisites)
        
    Set Prerequisite(piPrerequisites) = Unit
'    iPrerequisiteDelay(piPrerequisites) = iDelay

End Property

Open in new window


The test code I have used to instantiate the units and set their links is as follows

Sub Test_linking()

    Dim UnitA As clsProcessUnit
    Dim UnitB As clsProcessUnit
    Dim UnitC As clsProcessUnit
    
    Set UnitA = New clsProcessUnit
    Set UnitB = New clsProcessUnit
    Set UnitC = New clsProcessUnit
    
    UnitA.Name = "First Unit"
    UnitB.Name = "Second Unit"
    UnitC.Name = "Third Unit"
        
    UnitA.Reset
    UnitB.Reset
    UnitC.Reset
    
    UnitB.Requires = UnitA
    UnitC.Requires = UnitB

    UnitA.DisplayLinks
    UnitB.DisplayLinks
    UnitC.DisplayLinks
    
End Sub

Open in new window


Ideally, I would like to use one statement to set the name and the numeric value associated with the link, where I use the "UnitA.Requires = " etc.
0
Comment
Question by:sjgrey
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 37737202
You could use a function or sub in the class that takes two arguments, and calls the relevant internal properties (that way you can still assign either value individually if needed).
0
 
LVL 1

Author Comment

by:sjgrey
ID: 37739644
I'll need to look at my notes to see how to do that - later today.  Thanks
0
 
LVL 1

Author Closing Comment

by:sjgrey
ID: 37744689
I've come to the conclusion that I need a new object class to represent the links, probably using a function as suggested to set them up
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

867 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