Salesforce

How Do I Determine the Type and Corresponding Magic xpa Attribute of a Variant Value Belonging to (Magic xpa 4.x)

« Go Back

Information

 
Created BySalesforce Service User
Approval Process StatusPublished
Objective
Description

How Do I Determine the Type and Corresponding Magic xpa Attribute of a Variant Value Belonging to a COM Object? (Magic xpa 4.x)

Many COM objects use the VT_VARIANT data type. The definition of the VT_VARIANT, is, in essence, that it can hold any data type. So when you see a parameter of this type, you don’t necessarily know what is being passed.

In practice, you will usually know what the object is expecting or sending because you are copying an example, or you have the documentation for the object. Magic xpa is very good at converting the data for you, so you don’t usually need to do the conversions manually. For instance, if you accept a VT_VARIANT type in a numeric variable, and the object was in fact passing back a number, then the work is done for you.

However, it could be the case that one object sends back a numeric in a variant for one call, and an alpha for another call, in which case you would have to accept the data in a BLOB and then figure out what it contains.

One way to do this is with the VariantAttr() function. This function accepts a BLOB as a parameter, and returns the data type of the variant as a one character code. That code can then be used with the VariantGet() function to extract the data. You can also use the VariantType() function, which returns a code specifying the underlying data type (such as VT_l8).

Extracting the attribute type using VariantAttr()

The syntax of VariantAttr() is:

VariantAttr(Variant)

where:

  • Variant: The BLOB that has your Variant.

This returns a letter that represents the Magic xpa attribute type. See Variant Data Attributes for a list of those types.

In this example, the variant is a VT_DATE type, so the letter ‘D’ is returned, corresponding to the Magic xpa “Date” attribute. Now that we have the attribute type, we can use that with the VariantGet() function to fetch the data out of the variant into the proper variable.

Extracting the data type using VariantType()

The syntax of VariantType() is:

VariantType(Variant)

where:

  • Variant: The BLOB that has your Variant.

This returns a letter that represents the Magic xpa attribute type. See Variant Data Types for a list of those types.

In this example, the variant is a VT_DATE type, so the number 7 is returned.

Reference
Attachment 
Attachment