PRB: Behavior of the Format Function Changes from Visual Basic 5.0 to Visual Basic 6.0 (297882)



The information in this article applies to:

  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Learning Edition for Windows 5.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0

This article was previously published under Q297882

SYMPTOMS

The Format function produces different results after you migrate a Visual Basic application from version 5.0 to version 6.0.

CAUSE

This problem can occur if you do not specify enough placeholders. The number of placeholder characters must equal the number of characters in the string that you are trying to format. In this case, the Format function must make assumptions about how to fill in the remaining characters.

For example, suppose that you want to format the string "Microsoft", so you make the following call to the Format function:
Format("Microsoft","@-@")
				
Because you have not supplied enough at signs (@), the Format function must decide from which end it must start to fill in the remaining characters. The output differs depending on which end the function starts, which differs between Visual Basic versions 5.0 and 6.0.

RESOLUTION

To resolve this problem, always supply the correct number of placeholder characters. If you use the preceding example, change the call to the Format function as follows:
Format("Microsoft","@-@@@@@@@@")
				

MORE INFORMATION

Suppose that you make the following call to the Format function:
Format("Microsoft","@-@")
				
In Visual Basic 5.0, the placeholders are filled in from right to left, and the following output is returned:
Microsoft-t
				
However, this behavior changes in Visual Basic 6.0. In Visual Basic 6.0, the placeholders are filled in from left to right. As a result, the following output is returned:
M-icrosoft
				

Modification Type:MajorLast Reviewed:5/13/2003
Keywords:kbpending kbprb kbString KB297882