EncodeText Method  
 

Encodes a string using base64 or quoted-printable encoding.

Syntax

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

Parameters

MessageText
A string that contains the text which will be encoded.
EncodedText
A string variable passed by reference which will contain the encoded text when the method returns.
CharacterSet
An optional integer value which specifies the character set to use when encoding the text. If no character set is specified, this method will default to using UTF-8.
EncodingType
An optional integer value which specifies the content encoding type. 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 encoded text. A return value of zero indicates no text has been encoded. 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.

Remarks

This method provides a means to encode text using either base64 or quoted-printable encoding. It is not necessary to use this method to encode text when assigning a value to the Text property. The control will automatically encode message text which contains non-ASCII characters using the character set specified when the message is created.

If the CharacterSet parameter s specified, the method will convert the message text using the ANSI code page associated with the character set, and then the text will be encoded. If the parameter is omitted, the message text will be converted to UTF-8 and then encoded.

If the mimeCharsetUTF16 character set is specified, you must also specify mimeEncodingBase64 as the encoding method. Other encoding methods are not supported and this will cause the method to fail. It is not recommended you encode text as UTF-16 unless there is a specific requirement to use that character set.

It is recommended that you use the mimeCharsetUTF8 character set whenever possible. It is capable of encoding all Unicode code points, and is a standard for virtually all modern Internet applications. In most cases, it is preferable to use mimeEncodingBase64 as the encoding method, with quoted-printable encoding only used for legacy support.

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, DecodeText Method