Visual Basic Reference

Visual Studio 6.0

GetData Method (DataObject Object)

See Also    Example    Applies To

Returns data from a DataObject object in the form of a variant.


object.GetData (format)

The GetData method syntax has these parts:

Part Description
object Required. An object expression that evaluates to an object in the Applies To list.
format A constant or value that specifies the data format, as described in Settings. Parentheses must enclose the constant or value. If format is 0 or omitted, GetData automatically uses the appropriate format.


The settings for format are:

Constant Value Description
vbCFText 1 Text (.txt files)
vbCFBitmap 2 Bitmap (.bmp files)
vbCFMetafile 3 metafile (.wmf files)
vbCFEMetafile 14 Enhanced metafile (.emf files)
vbCFDIB 8 Device-independent bitmap (DIB)
vbCFPalette 9 Color palette
vbCFFiles 15 List of files
vbCFRTF -16639 Rich text format (.rtf files)


These constants are listed in the Visual Basic (VB) object library in the Object Browser.

It's possible for the GetData and SetData methods to use data formats other than those listed in Settings, including user-defined formats registered with Windows via the RegisterClipboardFormat() API function. However, there are a few caveats:

  • The SetData method requires the data to be in the form of a byte array when it does not recognize the data format specified.

  • The GetData method always returns data in a byte array when it is in a format that it doesn't recognize, although Visual Basic can transparently convert this returned byte array into other data types, such as strings.

  • The byte array returned by GetData will be larger than the actual data when running on some operating systems, with arbitrary bytes at the end of the array. The reason for this is that Visual Basic does not know the data's format, and knows only the amount of memory that the operating system has allocated for the data. This allocation of memory is often larger than is actually required for the data. Therefore, there may be extraneous bytes near the end of the allocated memory segment. As a result, you must use appropriate functions to interpret the returned data in a meaningful way (such as truncating a string at a particular length with the Left function if the data is in a text format).

Note   Not all applications support vbcfBitmap or vbCFPalette, so it is recommended that you use vbCFDIB whenever possible.