How to Print the ASCII Character Set in Visual BasicLast reviewed: June 21, 1995Article ID: Q75857 |
The information in this article applies to:
SUMMARYThe default font used by Visual Basic is the standard ANSI character set. To display the ASCII character set, which is more commonly used in MS-DOS-based applications, you must call the two Windows API functions GetStockObject and SelectObject. In addition, to display the unprintable characters such as TAB, linefeed, and carriage return characters, you need to use the TextOut Windows API function because the standard Visual Basic printer object does not display the unprintable characters. By using the Windows API TextOut function, you circumvent the Visual Basic printer object and therefore allow all the characters to be displayed.
MORE INFORMATIONWindows supports a second character set, referred to as the OEM character set. This is generally the character set used internally by MS-DOS for screen display at the MS-DOS prompt. The character codes 32 to 127 are usually identical for the OEM, ASCII, and ANSI character sets. The ANSI characters represented by the remaining character codes (codes 0 to 31 and 128 to 255) are generally different from characters represented by the OEM and ASCII character sets. However, the OEM and ASCII character sets are identical for these ranges. Under the ASCII and OEM character sets, the character codes 128 to 255 correspond to the extended ASCII character set, which includes line drawing characters, graphics characters, and special symbols. The characters represented by this range of character codes generally differ between the ASCII (or OEM) and ANSI character sets. To change the selected font from ANSI to the OEM ASCII font, you must get a handle to the OEM character set by calling GetStockObject. When this handle is passed as an argument to SelectObject, the ANSI font will be replaced by the OEM ASCII font. This API function also returns the handle to the font object previously used. Once you finish displaying the desired characters, you should call SelectObject again to reselect the original font object. NOTE: There is also an API function called DeleteObject. This function need not be called to delete a stock object. The purpose of this API function is to delete objects loaded with the API function GetObject. Here is the syntax for the functions:
GetStockObject% (nIndex%)nIndex%
Specifies the type of stock object desired. Use the constant OEM_FIXED_FONT to retrieve the handle to the OEM character set. The value of this constant is 10.Return Value
The return value identifies the desired logical object if the function is successful. Otherwise, it is NULL. SelectObject% (hDC%, hObject%)hDC%
Identifies the device context.hObject%
Identifies the object to be selected. Use the return value from GetStockObject% (above) to select the OEM character set.Return Value
The return value identifies the handle to the object previously used. This value should be saved in a variable such that SelectObject can be called again to restore the original object used. It is NULL if there is an error. Step-by-Step ExampleThe following example steps demonstrate how to create a program that prints ASCII characters.
ASCII and ANSI Character SetsFor a listing of the ASCII and ANSI character sets, see the Visual Basic Help menu. American Standard Code for Information Interchange (ASCII) is the 7-bit character set widely used to represent letters and symbols found on a standard United States keyboard. The ASCII character set is the same as the first 128 characters (0 to 127) in the American National Standards Institute (ANSI) character set. The ANSI character set uses all 8 bits in a byte, and includes 256 characters (0 to 255). Characters 128 to 255 are sometimes called the extended-ASCII characters.
REFERENCES
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |