Ecoulter

VBA AF Wrapper Extension GetValueByTime for Processbook

Discussion created by Ecoulter on Jun 6, 2013
Latest reply on Jun 7, 2013 by Marcos Vainer Loeff

I have been extending the original base wrapper to allow me to pull data based on a time.  I am running into an issue that the value doesn't change for each interval and I'm not even sure where the number it is getting is coming from.  If someone could take a look at what I've done and see if you notice any mistakes, that would be helpful.

 

 First the change to the Wrapper:

 

 

 
 // Gets the current value for an attribute path
        [ComVisible(true)]
        public string GetAttributeValue(string fullAttributePath)
        {
            AFObject obj = AFObject.FindObject(fullAttributePath);
            AFAttribute attr = obj as AFAttribute;

            if (attr == null) return "";

            return attr.GetValue().ToString();
        }
        [ComVisible(true)]
        public string GetAttributeValueByTime(string fullAttributePath, DateTime dt)
        {
            AFObject obj = AFObject.FindObject(fullAttributePath);
            AFAttribute attr = obj as AFAttribute;

            if (attr == null) return "";
            AFTime time = new AFTime(dt);

            return attr.GetValue(time).ToString();
        }

        // Gets the current value for an attribute of a given element path
        [ComVisible(true)]
        public string GetAttributeValueForElement(string elementPath, string attribute)
        {
            return GetAttributeValue(elementPath + @"|" + attribute);
        }
        [ComVisible(true)]
        public string GetAttributeValueForElementByTime(string elementPath, string attribute, DateTime dt)
        {
            return GetAttributeValueByTime(elementPath + @"|" + attribute, dt);
        }

 Now the VBA Code:

 

 

 
Public Sub GetAttrValue()
    
    Set AFW = New Wrapper
    
    Dim dt As Date
    dt = Now
    If (Hour(dt) > last) Then
        Dim itor As Integer
        ListBox1.Clear
        itor = 0
        last = Hour(dt)
        Do While (itor <= last)
            Dim dv As String
            dv = Month(Now) & "/" & Day(Now) & "/" & Year(Now) & " " & itor & ":00:00"
            ListBox1.AddItem (dv & " - " & AFW.GetAttributeValueForElementByTime("\\BATTLESTAR\TF\Rev Qual Meters", "City Load", DateValue(dv)) & "MW")
            itor = itor + 1
        Loop
        
        
    End If
    
    
       
    
End Sub

 The Result when this code is run looks like this:

 

3487.Screen-Shot-2013_2D00_06_2D00_06-at-9.16.29-AM.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Outcomes