Calling FormatX$ Functions Without DECLARE BYVAL May Hang (73799)






This article was previously published under Q73799

SUMMARY

The following information applies to the add-on library of FormatX$ functions provided with Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS and MS OS/2.

The FormatX$ functions create strings containing formatted numeric values for date, time, or monetary values. These functions expect two arguments: a numeric variable passed by value, and a string passed by reference. If the numeric argument is passed to a FormatX$ function by reference accidentally, the program may hang.

MORE INFORMATION

There are five FormatX$ functions, one for each Basic numeric data type. Below are the function declarations as they appear in the FORMAT.BI include file provided with Basic PDS:
   DECLARE FUNCTION FormatI$ (BYVAL a%, b$)
   DECLARE FUNCTION FormatL$ (BYVAL a&, b$)
   DECLARE FUNCTION FormatS$ (BYVAL a!, b$)
   DECLARE FUNCTION FormatD$ (BYVAL a#, b$)
   DECLARE FUNCTION FormatC$ (BYVAL a@, b$)
				
If you do not include these function declarations in your Basic programs, make certain that you declare the functions to receive the numeric parameter BYVAL (by value) or the program may hang. The following code demonstrates the hanging behavior. To run the program, you should start the QBX.EXE environment using the /L option to load the DTFMTER.QLB Quick library (for example: qbx /l dtfmter.qlb).
   '*** This line should say 'BYVAL a#' for the first parameter ***
   DECLARE FUNCTION FormatD$ (a#, b$)
   DECLARE FUNCTION TimeValue# (t$)
   timeNow# = TimeValue(TIME$)
   PRINT FormatD$(timeNow#, "HH:MM:SS")
   END
				
The above program will hang on the PRINT statement where the FormatD$ function is invoked. The program will run correctly if the declaration for FormatD$ is changed to include the BYVAL keyword for the first parameter:
   DECLARE FUNCTION FormatD$ (BYVAL a#, b$)
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB73799