DecodeText Method  

Decode a string which was previously encoded using base64 or quoted-printable encoding.


object.DecodeText( EncodedText, MessageText, [CharacterSet], [EncodingType] )


A string which contains the encoded text which should be decoded.
A string variable passed by reference which will contain the decoded text when the method returns.
An optional integer value which specifies the character set to use when decoding the encoded text. If this value does not match the character set used when the text was originally encoded, the resulting output text may be invalid. If no character set is specified, this method will default to using UTF-8.
An optional integer value which specifies the content encoding to use when decoding the text. It may be one of the following values:
Value Constant Description
4 mimeEncodingQuoted Quoted-printable encoding is designed for textual messages where most of the characters are represented by the ASCII character set and is generally human-readable. Non-printable characters or 8-bit characters with the high bit set are encoded as hexadecimal values and represented as 7-bit text. Quoted-printable encoding is typically used for messages which use character sets such as ISO-8859-1, as well as those which use HTML.
5 mimeEncodingBase64 Base64 encoding converts binary or text data to ASCII by translating it so each base64 digit represents 6 bits of data. This encoding method is commonly used with messages that contain binary data (such as binary file attachments), or when text uses extended characters that cannot be represented by 7-bit ASCII. It is recommended that you use base64 encoding with Unicode text. This is the default encoding type used by this method.

Return Value

The method returns the number of characters of decoded text. A return value of zero indicates no text has been decoded. If the method fails, it will return -1 and the LastError property can be used to determine the cause of the failure. In most cases where the method fails, it is because an invalid character set or encoding type has been specified.


This method provides a means to decode text that was previously encoded using either base64 or quoted-printable encoding. In most cases, it is not necessary to use this method because the message parser will detect which character set and encoding was used, then automatically decode the message text if necessary.

The value of the CharacterSet parameter does not affect the resulting output text, it is only used when decoding the input text. The previous contents of the MessageText string will be replaced by the decoded text, and the output string will always be Unicode.

If the CharacterSet parameter is specified as mimeCharsetUTF16, the encoding type must be mimeEncodingBase64. Other encoding methods are not supported for Unicode strings and will cause the method to fail. In most cases, it is preferable to always use mimeEncodingBase64 as the encoding method, with quoted-printable encoding only used for legacy support. If an unsupported encoding type is specified, this method will return -1 and the output text string will be empty. This method cannot be used to decode uuencoded text.

If you are developing your application using Visual Basic 6.0, the IDE does not provide complete support for Unicode. The decoded text may appear to be corrupted when examining it in the debugger. This is because the IDE will attempt to convert the string to ANSI using the system default code page. To display Unicode text correctly, you must use controls which are Unicode aware, such as the Microsoft InkEdit control.

See Also

Encoding Property, Text Property, ComposeMessage Method, CreatePart Method, EncodeText Method