Titus Information Systems, Inc.

Standard Library
Conversion Functions

Many applications require user input to be converted to and from internal storage structures and formatted for easy user data entry.  Naturally, this input must be validated as well, but several special types of data entry are beyond the basic capabilities of standard MFC edit box validations and conversions.  The Standard Utility Library provides functions to accomplish these conversions.  The following functions may be accessed from a C++ function utilizing the standard name-mangling call interface.  In addition, some of the functions may be called from applications written in other languages, such as Visual Basic for Applications.  These functions are noted by a pseudo function call in square brackets at the end of the description; for example, [VpI2(0x40)].  To call these functions, use the following header:

Declare Function VpI2 Lib "TISLIBP.DLL" (ByVal Routine As long, ByVal ArgumentOne As ArgumentType, ByVal ArgumentTwo As ArgumentType, ByVal ReturnCode As ReturnType)

Routine should be initialized to the number in parentheses.  Specify the arguments to the function, however many there are, with the appropriate types.  Finally, specify a variable for the return code with the appropriate type.

The following is a description of the conversion functions and the arguments necessary to properly call them:

char*StringFromInteger(int Number, BOOL Comma)
char*StringFromInteger(DWORD Number, BOOL Comma)
char*StringFromInteger(UINT Number, BOOL Comma)
char*StringFromInteger(char Number, BOOL Comma)
char*StringFromInteger(BYTE Number, BOOL Comma)
These functions return a string representation of Number with leading zeros suppressed.  If Comma is TRUE, commas are used to separate the digits by orders of thousands.


char*StringFromInteger(int Number, UINT Decimal)
This function returns a string representation of Number with leading zeros suppressed.  Decimal indicates the scaling of Number, and, if it is greater than zero, a decimal point will be placed appropriately.  Please note that Decimal must be of type UINT, not of type int.
char*DollarFromInteger(DWORD Number)
char*DollarFromInteger(UINT Number)
These functions return a string representation of Number with leading zeros suppressed, a leading dollar sign, and commas separating the digits by orders of thousands.
char*StringFromCharacter(char*LenStr)
This function returns a null-terminated string from a non-terminated string containing the length in the first two bytes.
char*StringFromCharacter(char*Field, int Length)
This function returns a null-terminated string containing the characters in a Field that is Length characters long.
char*StringFromNumeric(char*Field, int Length)
This function returns a null-terminated string representation of the number in Field.  The result has all leading zeros removed.  (Length / 10) is the number of digits to the left of the decimal point, and (Length % 10) is the number of digits to the right of the decimal point.  For example, to convert a PIC 9(6)V99 field to a string for display, use a Length of 62.  The maximum size of Field is 18 digits.
char*StringFromPacked(char*Field, int Length)
This function returns a null-terminated string containing digits representing a the packed decimal value in Field.  The result has all leading zeros removed.  (Length / 10) is the number of digits to the left of the decimal point, and (Length % 10) is the number of digits to the right of the decimal point.  For example, to convert a PIC S9(9)V99 USAGE COMP-3 field to a string for display, use a Length of 92.  The maximum size of Field is 18 digits.  [VpI2(0x40)]
int IntegerFromString(CString Field)
This function returns a 32-bit integer from a CString (or null-terminated string).
int IntegerFromString(CString Field, int Decimal)
This function returns a 32-bit integer from a CString (or null-terminated string) containing a character representation of a fixed-point real number.  The returned integer is scaled by the number in Decimal.  Use this function to store fixed-point real numbers with any loss of precision.
int IntegerFromDollar(CString Field)
This function returns a 32-bit integer from a CString (or null-terminated string) containing a character representation of a dollar amount.  The dollar sign and all commas are removed and the returned integer is scaled by 100.
void CharacterFromString(CString Input, char*LenStr)
This function copies the characters in Input into String.  Input.GetLength() is put into the first two bytes of String.  String is not null-terminated.
void CharacterFromString(CString Input, char*Output, int Length)
This function copies the characters in Input into Output.  If Length is less than Input.GetLength(), Input is truncated.  If Length is greater than Input.GetLength(), Output is blank filled.
void CharFromString(CString Input, char*Output, int Length)
This function copies Input to Output.  Output is null-terminated.  If Length is less than Input.GetLength() - 1, Input is truncated.
BOOL NumericFromString(CString InStr, char*OutStr, int Length)
This function converts InStr, which may contain a decimal point, into numeric data in OutStr.  (Length / 10) is the number of digits to the left of the implied decimal point, and (Length % 10) is the number of digits to the right of the implied decimal point.  For example, PIC 9(6)V99 has a Length of 62.
BOOL PackedFromString(CString InStr, char*OutStr, int Length)
This function converts a representation of a number in InStr into packed decimal format in OutStr.  The value of the function determines the success of the conversion.  (Length / 10) is the number of digits to the left of the implied decimal point, and (Length % 10) is the number of digits to the right of the implied decimal point.  For example, PIC S9(9)V99 USAGE COMP-3 has a Length of 92.  [VpI3(0x41)]
void NumericFromInteger(int Value, char*Result, int Length)
void NumericFromInteger(DWORD Value, char*Result, int Length)
void NumericFromInteger(UINT Value, char*Result, int Length)
void NumericFromInteger(char Value, char*Result, int Length)
void NumericFromInteger(BYTE Value, char*Result, int Length)
These functions convert Value into numeric data in Result.  Length is the number of digits in result.
UINT IntegerFromNumeric(char*Field, int Length)
This function returns a 32-bit unsigned integer from the numbers in a Field that is Length characters long.
void PackedFromInteger(UINT Value, char*Result, int Length)
This function converts Value into packed decimal format in Result.  Length is the number of digits in Result.  For example, PIC S9(9)V99 USAGE COMP-3 has a Length of 11.  Note that the result will be scaled the same as the picture clause; i.e., the implied decimal point is ignored.  [VpI3(0x43)]
UINT IntegerFromPacked(char*Field, int Length)
This function returns a 32-bit integer from the packed decimal value in Field.  Length is the number of digits in Field.  The result will be scaled the same as the picture clause; i.e., the implied decimal point is ignored.  For example, 12.34 stored in PIC S9(9)V99 USAGE COMP-3 will be converted to an integer with a value of 1,234.  [VpI2(0x42)]
void HexFromInteger(int Value, char*Result, int Length)
This function converts Value into a string of Hexadecimal digits in Result.  Length is the number of digits in Result, which will be filled with leading zeros as necessary.  Result is not null-terminated.
CString StringFromPercent(UINT Count, UINT Base)
This function returns a string representation of the ratio of Count to Base expressed as a percent to one decimal place.
DWORD TcpipFromString(CString Field)
This function converts a character representation of a TCP/IP address (nnn.nnn.nnn.nnn) into a 32-bit unsigned integer for use in API function calls.
char*StringFromTelephone(char*Field, int Length)
This function returns a null-terminated string with the digits of a telephone number formatted for display.  Length may be 7, 10, 14.  A seven-digit number is converted to "nnn-nnnn".  A ten-digit number is converted to "(nnn) nnn-nnnn".  A fourteen-digit number is converted to "(nnn) nnn-nnnn X nnnn".
BOOL TelephoneFromString(CString Input, char*Output, int Length)
This function converts telephone number in Input from display format to storage format in Output.  Length may be 7, 10, 14.  When 7, the input string must be in the format "nnn-nnnn".  When 10, the input string must be in the format "(nnn) nnn-nnnn".  When 14, the input string must be in the format "(nnn) nnn-nnnn X nnnn".
char*StringFromTitle(char Code)
This function returns a null-terminated string corresponding to the specified title code.  The codes are as follows:
M:   "Mr." R:  "Mrs." I:   "Miss"
D:  "Dr." S:  "Ms." V:  "Rev."
E:  "Sen." Q:  "Rep." G:  "Gov."
H:  "Hon." J:  "Jdg." F:  "Prof"
A:  "Adm." 1:  "Gen." C:  "Col."
2:  "Maj." P:  "Cpt." 3:  "Cdr."
4:  "Lcd." L:  "Lt." 5:  "Ltj."
K:  "Sgm." T:  "Sgt." B:  "Cpl."
6:  "Cpo." O:  "Po." W:  "Cwo."
X:  "Ens." U:  "Afc." Y:  "Pfc."
Z:  "Pvt." N:  "" blank:  "Unknown".
char*StringFromSuffix(char Code)
This function returns a null-terminated string corresponding to the specified marital status code.  The codes are as follows:
J:  "Jr." S:  "Sr." 1:  "I"
2:  "II" 3:  "III" 4:  "IV"
5:  "V" 6:  "VI" 7:  "VII"
8:  "VIII" 9:  "IX" 0:  "X"
P:  "Ph.D." B:  "Ed.D." M:  "M.D."
T:  "D.O." C:  "D.C." O:  "O.D."
F:  "D.P.M." G:  "D.D.M." V:  "D.V.M."
D:  "D.D.S." H:  "D.M.D." R:  "R.N."
Q:  "L.P.N." A:  "C.P.A." I:  "A.I.A."
U:  "C.L.U." L:  "J.D." E:  "Esq."
Z:  "Ret." N:  "" blank:  "Unknown"
char*StringFromSex(char Code)
This function returns a null-terminated string corresponding to the specified gender code.  The codes are as follows:
M:  "Male" F:  "Female" blank:  "Unknown".
char*StringFromMarital(char Code)
This function returns a null-terminated string corresponding to the specified marital status code.  The codes are as follows:
M:  "Married" S:  "Single" W:  "Widowed".
D:  "Divorced" P:  "Separated" blank:  "Unknown".
void ClearField(char*Output, int Length)
This function writes a blank into every character of Output, which is Length characters long.  Output is not null-terminated.
void CopyField(char*Output, char*Input, int Length)
This function copies characters from Input to Output, which are both Length characters long.  Neither Input nor Output are null-terminated.
CString MessageFromCode(CString Message, short Code)
This function returns a CString with the text "Return Code: n" appended to Message.  The decimal value of Code is converted to a string "n".
void DisplayLastError(CString Message)
This function uses AfxMessageBox with flags "MB_OK + MB_ICONSTOP" to display the system error code description appended to Message.  GetLastError() is used to get the error code, and FormatMessage() with the FORMAT_MESSAGE_FROM_SYSTEM flag is used to get the description.
BOOL BackupFromFileName(CString&File)
This function replaces the extension of the path name in File with ".BAK".  The value of the function indicates the success of the conversion.


[ Stand-alone Programs | Standard Library | Utility Functions | COBOL Functions ]
[ Windows NT Library | COBOL Library | COBOL Interface | Command Prompt Abbreviations | Purchase Instructions ]

[ Home | Areas of Expertise | "We Do Windows" | Clients and Projects | Software Samples | Package Software Available ]
[ Contact Information | Business Software Philosophy | Church Software Philosophy ]
All contents of this web site are Copyright © Titus Information Systems, Inc., Phoenix, Arizona, U.S.A.