The information in this article applies to:
SYMPTOMSThe pound (#) sign does not serve as a place holder for blank spaces when used with the Format$ function to reformat numbers as strings. If a pound sign place holder is not filled by a digit, Format$ truncates that digit position and will not replace that position with a space. This may be undesirable behavior if you are attempting to right justify the numeric digits within the string. CAUSEVisual Basic Format$ function handles the pound sign (#) place holder differently from the way the it's handled in the Print Using statement found in other Basic products. In the Print Using statement, a pound sign place holder is replaced by a space when no numeric digit occupies that position. By using the Print Using statement, you can right justify a formatted numeric string by using the pound sign as place holders for the number. Visual Basic does not support the Print Using statement, so you need to use additional code to right justify a string using the Visual Basic Format$ function. An example is given below. WORKAROUNDTo work around the problem, use a monospaced font, such as Courier, and use the Len function to determine how many spaces need to be added to the left of the string representation of the number to right justify the result. Here is the example code:
STATUSThis behavior is by design. MORE INFORMATION
Page 121 of the "Microsoft Visual Basic: Language Reference" for version
1.0 regarding the Format$ function doesn't specify how the pound sign is
handled. When there is no numeric digit to fill the pound sign place
holder, the manual does not specify whether the pound sign is replaced by
a space or truncated. The documentation should reflect how the pound sign
is handled by the Format$ function.
The above example causes two leading spaces to be added to the resulting
string representation of the variable myvar when the value of myvar is
printed to the screen.However, when used with the Visual Basic Format$ function, the same pound sign format switch (#) does not work as a placeholder for spaces:
The Visual Basic Format$ function yields a formatted string representation
of myvar with no leading spaces. This may not be the result you expected
(for example, when myvar = 1.23). You may have expected the formatted
result to have one leading space allowing you to right justify the number,
but no leading space is added.The following code sample produces an output of right justified numbers in Microsoft QuickBasic version 4.5:
The following code sample produce an output of left justified numbers in
Visual Basic:
Click the form to print the numbers. These numbers will be left justified,
instead of right justified as may be desired.
Additional query words: 2.00 3.00 4.50 alignment aligned align right-justify docerr
Keywords : |
Last Reviewed: September 16, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |