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

x
?
Solved

Setting linked parameters/properties in a VBA class

Posted on 2012-03-18
3
Medium Priority
?
196 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 1500 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

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

618 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