Partilhar via


COMVariant.noValue Method

Definition

Deletes the contents of an existing COMVariant object and enables it to act as an unspecified argument when it is used in the COMDispFunction.call method or the COM class.

public:
 virtual void noValue();
public virtual void noValue ();
abstract member noValue : unit -> unit
override this.noValue : unit -> unit
Public Overridable Sub noValue ()

Remarks

A no-value variant can be used when a COM method has parameters that can be null. It indicates to the COM object that the argument has not been specified and that it must use its own default value. When you are calling methods on a COM object, the unspecified argument can also be specified by using the COMArgument::NoValue enum. Note that this enum cannot be used when calling through the COMDispFunction class.

The following example shows how to call the COM.multiply method with the third argument unspecified. The code below contains a hypothetical COM object ("MyCOM.Object"), and will therefore not run in Finance and Operations, unless such an object is created outside Finance and Operations.

{ 
    COM        com; 
    COMVariant varArg1 = new COMVariant(); 
    COMVariant varArg2 = new COMVariant(); 
    COMVariant varArg3 = new COMVariant(); 
    COMVariant varRet  = new COMVariant(COMVariantInOut::OUT_RETVAL); 
    real       ret; 
    InteropPermission perm; 
    // Set code access permission to help protect use of COM object 
    perm = new InteropPermission(InteropKind::ComInterop); 
    if (perm == null) 
    { 
        return; 
    } 
    // Permission scope starts here 
    perm.assert(); 
    com = new COM("MyCOM.Object"); 
    // Specify arguments for the multiply method 
    varArg1.float(123); 
    varArg2.float(456); 
    varArg3.noValue(); 
    varRet = com.multiply(varArg1, varArg2, varArg3); 
    // or
    varRet = com.multiply(varArg1, varArg2, COMArgument::NoValue); 
     ret = varRet.double(); 
    // ret is now 56088 (123*456) 
    // Close code access permission 
    CodeAccessPermission::revertAssert(); 
}

Applies to