Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

OEMTOANSI(), ANSITOOEM()

These functions convert text between the IBM character set and its closest equivalent in ANSI. Great way to forever and hopelessly mangle text. Use Code Pages instead. OEMTOANSI() was a great idea for U.S. translation of text from DOS to Windows before the code page support of FoxPro version 2.5a, but far better ways exist now. OEMTOANSI() converts characters 15, 20, 21 and those of values 128 and above from their values on the IBM-PC character set to their equivalents on the Windows platform, and ANSITOOEM() attempts to go the other way.

That’s great, you say, but what about those characters, such as line and box drawing characters, that don’t have a close equivalent? Mangled right into vertical bars and plus symbols, they are, matey. Since these characters lose their original value, you cannot run the opposite function back on them and hope to come out with the original string. Use the AS clauses of functions such as MODIFY FILE or the CPCONVERT() function for fields.

Usage

cRetVal = OEMTOANSI( cString )
cRetVal = ANSITOOEM( cString )

Example

@ $+1,0 say OEMtoANSI("Jos"+chr(130)) font "Times",9
@ $+1,0 say ANSItoOEM("José") font "FoxFont",9

These two examples show us the translation both ways. In the first example, we take “Jos” and CHR(130), which shows up as a black block in most Windows fonts, and translate it to the proper Windows characters to display “José.” In the second example, we display this name in FoxFont, using the ANSITOOEM() function to map the accented letter to its correct equivalent in FoxFont.

In case you’re curious, “OEM” stands for “Original Equipment Manufacturer” and was a code word for IBM’s ASCII. This function doesn’t translate all manufacturers’ codes—just one. ASCII, if you’re really dying to know, is the American Standard Code for Information Interchange—which it is not, being an IBM invention foisted on the world as a standard. Kind of like Windows. ANSI, on the other hand, stands for the American National Standards Institute; they really do make standards.

See Also

Asc(), Chr(), CPConvert(), CPCurrent(), CPDBF(), Modify File, Modify Command