This document is archived and information here might be outdated.  Recommended version.


Using value tables (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Using geoprocessing > Working with multiple datasets > Using value tables (ArcObjects .NET 10.6 SDK)

Using value tables


About using value tables

A value table is a flexible object that can be used as input for a multivalue parameter. Examples of multivalue parameter values focus on the text value of the parameter that can become difficult to use when there are numerous values with complex paths. The value table is used to organize the values into a table so values can be easily added or removed, eliminating the complexity of parsing a multivalue text string. The table can be thought of as a virtual matrix of values that is not persisted as an actual table because it is a device for managing many values in a program.

Creating and populating a value table

A value table can contain many columns. Each column corresponds to a value in the parameter being defined. Intersect, for example, requires the path to a dataset or a layer name and an optional priority rank for each input entry. A value table for Intersect requires two columns, one for the data and one for the priority rank.
The following code example shows how to create and populate a value table for Intersect. In this example, you need to add a reference to the ESRI.ArcGIS.Geoprocessing assembly to have access to the GPValueTableObject class. AddRow's row argument is space delimited. Any value used in the row argument that contains spaces must be enclosed in quotation marks. In the following example, a value table with two columns has a feature class and an index value added; for example, vt.AddRow("'c:/temp/land use.shp' 2"):
[C#]
public void ExampleUsingValueTables(Geoprocessor GP)
{

    // Create a value table with two columns.
    IGpValueTableObject vtobject=new GpValueTableObjectClass();
    vtobject.SetColumns(2);

    // Iterate the enumeration of feature classes and add them to the value table.
    // In this case, the inputs and ranks are being set for Intersect.
    GP.SetEnvironmentValue("workspace", @"C:\GP\PortlandOR.gdb");
    IGpEnumList fcColl=GP.ListFeatureClasses("*", "POLYLINE", "");
    string inputfeatures=fcColl.Next();
    object row="";

    while (inputfeatures != "")
    {

        if (inputfeatures == "streets")
        {

            row=inputfeatures + " 1";
            vtobject.AddRow(ref row);

        }
        else
        {

            row=inputfeatures + " 2";
            vtobject.AddRow(ref row);

        }

        inputfeatures=fcColl.Next();

    }

    IVariantArray pVarArray=new VarArrayClass();
    pVarArray.Add(vtobject);
    pVarArray.Add("C:\\Gp\\PortlandOR.gdb\\streets_bike");

    // Execute the Intersect tool.
    GP.Execute("intersect_analysis", pVarArray, null);

}
[VB.NET]
Public Sub ExampleUsingValueTables(ByVal GP As Geoprocessor)
    
    ' Create a value table with two columns.
    Dim vtobject As ESRI.ArcGIS.Geoprocessing.IGpValueTableObject=New ESRI.ArcGIS.Geoprocessing.GpValueTableObjectClass()
    vtobject.SetColumns(2)
    
    ' Iterate the enumeration of feature classes and add them to the value table.
    ' In this case, the inputs and ranks are being set for Intersect.
    GP.SetEnvironmentValue("workspace", "C:\GP\PortlandOR.gdb")
    Dim fcColl As ESRI.ArcGIS.Geoprocessing.IGpEnumList=GP.ListFeatureClasses("*", "POLYLINE", "")
    Dim inputfeatures As String=fcColl.Next()
    Dim row As Object=""
    
    Do While inputfeatures <> ""
        
        If inputfeatures="streets" Then
            
            row=inputfeatures & " 1"
            vtobject.AddRow(row)
            
        Else
            
            row=inputfeatures & " 2"
            vtobject.AddRow(row)
            
        End If
        
        inputfeatures=fcColl.Next()
        
    Loop
    
    Dim pVarArray As IVariantArray=New VarArrayClass()
    pVarArray.Add(vtobject)
    pVarArray.Add("C:\Gp\PortlandOR.gdb\streets_bike")
    
    ' Execute the Intersect tool.
    GP.Execute("intersect_analysis", pVarArray, Nothing)
    
End Sub
The following code example shows how a value table can be populated with a multivalue string that has been passed to a script as an argument, making it easy to extract each record:
[C#]
IGpValueTableObject vtobject=new GpValueTableObjectClass();

// Where input features is a multivalue of input feature classes.
vtobject.LoadFromString(inputfeatures);
[VB.NET]
Dim vtobject As ESRI.ArcGIS.Geoprocessing.IGpValueTableObject=New ESRI.ArcGIS.Geoprocessing.GpValueTableObjectClass()

' Where input features is a multivalue of input feature classes.
vtobject.LoadFromString(inputfeatures)


See Also:

How Intersect works




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):