PowerSNMP for .NET
CreateVariable(Enum,String) Method
Example 




A NodeName enum member that correlates to an intrinsic or imported MibNode.
A string representation of the value.
Creates a variable from the specified NodeName and value.
Syntax
Public Overloads Function CreateVariable( _
   ByVal nodeName As Enum, _
   ByVal value As String _
) As Variable
Dim instance As MibNodes
Dim nodeName As Enum
Dim value As String
Dim value As Variable
 
value = instance.CreateVariable(nodeName, value)
public Variable CreateVariable( 
   Enum nodeName,
   string value
)
public: Variable* CreateVariable( 
   Enum* nodeName,
   string* value
) 
public:
Variable^ CreateVariable( 
   Enum^ nodeName,
   String^ value
) 

Parameters

nodeName
A NodeName enum member that correlates to an intrinsic or imported MibNode.
value
A string representation of the value.

Return Value

A Variable with the specified value
Remarks

The value argument will be automatically converted into a SimpleType as applicable for the specified nodeName.

Intrinsic node names are provided by the NodeName enumeration. Node names from imported MIB code files are provided by the code file's Mib.NodeName enumeration.

Variables cannot be created with this method for objects defined in MIBs loaded at runtime; use a Variable constructor for this scenario. See Agent.Variables for a demonstration of creating variables from dynamically loaded MIBs.

Example
The following example demonstrates starting a simple agent with one variable.
private void button1_Click(object sender, EventArgs e)
{
    //Add a variable to the agent
    agent1.Variables.Add(agent1.Mib.GetByNodeName(NodeName.sysContact).GetIid(),
        agent1.Mib.CreateVariable(NodeName.sysContact, "Systems Admin"));

    //Start listening for requests
    agent1.Start(agent1_MessageReceived, null);
}

private void agent1_MessageReceived(Agent agent, RequestMessage request, object state)
{
    //Create and send a response whenever a request is received
    agent1.Send(agent1.CreateResponse(request), request.Origin);
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Add a variable to the agent
    agent1.Variables.Add(agent1.Mib.GetByNodeName(NodeName.sysContact).GetIid(), agent1.Mib.CreateVariable(NodeName.sysContact, "Systems Admin"))

    'Start listening for requests
    agent1.Start(AddressOf agent1_MessageReceived, Nothing)
End Sub

Private Sub agent1_MessageReceived(ByVal agent As Agent, ByVal request As RequestMessage, ByVal state As Object)
    'Create and send a response whenever a request is received
    agent1.Send(agent1.CreateResponse(request), request.Origin)
End Sub
See Also

Reference

MibNodes Class
MibNodes Members
Overload List

6.1.1.2
PowerSNMP for .NET Documentation Version 7.0
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic