Solved

Setting linked parameters/properties in a VBA class

Posted on 2012-03-18
3
190 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
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…

730 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