Solved

Setting linked parameters/properties in a VBA class

Posted on 2012-03-18
3
184 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

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!

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

763 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

10 Experts available now in Live!

Get 1:1 Help Now