(method - read/write)


For PCElements only, gets/sets the value of a state variable by name. If Code > 0 Then no variable by this name or the active circuit element is not a PCelement. 


Example


% Create DSS object

DSSObject = actxserver('OpenDSSEngine.DSS')

if ~DSSObject.Start(0),

                    disp('Unable to start openDSS');

                    return

end;

DSSText = DSSObject.Text;

DSSCircuit = DSSObject.ActiveCircuit;

DSSLines = DSSCircuit.Lines;

% Compile a model        

DSSText.Command = 'Compile C:\myPath\myModel.dss';

DSSActiveElement = DSSCircuit.ActiveCktElement;

% Activates the generator located in this model

DSSCircuit.SetActiveElement('Generator.G1');

% requests for state variable Vd

myStVar = 'Vd';

myCode = 0;

myVd = DSSActiveElement.VariableByName(myStVar, myCode);

if myCode == 0

    disp([myStVar,' value: ', num2str(myVd)]);

else

    disp('The variable does not exist');

end;


For writing operations, this method cannot be implemented using the basic late binding interpretation provided by some non-Windows native applications. Programs such MATLAB tend to have issues with it. If you are using MATLAB we recommend to use VariableName and VariableValue properties instead. The following example in VBA shows the method usage for writing operations:


Public Sub TestVariables()


Dim V As Variant, V2 As Variant

Dim N As Long


Dim Code As Long, AValue As Double, i As Long


DSSText.Command = "select generator.windgen1"


V = DSSCktElement.AllVariableNames  ' returns a variant array of strings

V2 = DSSCktElement.AllVariableValues


Debug.Print "All Variables"

For i = LBound(V) To UBound(V)

       Debug.Print i; " - "; V(i); " = "; V2(i)

Next i


AValue = DSSCktElement.VariableByIndex(2, Code)  'Returns a single variable at Index 3

Debug.Print "Avalue="; AValue; " number of Variables="; UBound(V) + 1


DSSCktElement.VariableByName("Slip", Code) = 0.01  ' Sets the Variable Torque to 100

AValue = DSSCktElement.VariableByName("Slip", Code)

Debug.Print "Slip="; AValue; " Code="; Code


DSSCktElement.VariableByIndex(4, Code) = 120#   ' sets the 4th variable to 100

AValue = DSSCktElement.VariableByIndex(4, Code)

Debug.Print "4th var="; AValue; " Code="; Code


End Sub