Solved

Setting linked parameters/properties in a VBA class

Posted on 2012-03-18
3
193 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
[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
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

688 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