Microsoft KB Archive/248459
Article ID: 248459
Article Last Modified on 1/11/2001
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
This article was previously published under Q248459
When the CanGrow property of a DataReport's label is set to True, the label automatically grows vertically if the text in the Caption property exceeds the preset size of the control. However, when assigning a multi-line string that contains leading spaces to the Caption property, the leading spaces are trimmed from all lines except the first line. The trimming also occurs even if character 32 (a blank space) is concatenated into the string.
If you are building the string dynamically in code, one workaround is to use character 160 rather than blank spaces or character 32. The following code creates a two-line string with five leading spaces in the first line and ten leading spaces in the second line:
Dim mystr as String mystr = " Five Leading Spaces" & vbCrLf mystr = mystr & String(10, 160) & "Ten Leading Spaces"
NOTE: This workaround assumes that you are using the standard ANSI character set. In the ANSI character set, character 160 is a blank space while in other character sets it represents an actual letter or symbol.
- Create a new Visual Basic Project. Form1 is created by default.
- From the Project menu, select Add Data Environment.
- Right-click Connection1 and select Properties.
- On the Provider tab, specify the Microsoft OLE DB Provider for ODBC Drivers.
- On the Connection tab, select a DSN that points to the Nwind.mdb database. Use Admin as the user name. On a system that does not have Access security set up, there is no password for the Admin user. If you have set up Access security, enter the password for the Admin user.
- Click the Test Connection button and, if the connection is successful, click OK.
- Right-click on Connection1 and choose Add Command.
- Right-click on Command1 and choose Properties.
- From the General tab, select the SQL Statement option.
Enter the following SQL Statement in the text box and choose OK:
SELECT * from categories where categoryid = 1
- From the Project menu, choose Add Data Report.
- Set the DataSource property to DataEnvironment1.
- Set the DataMember property to Command1.
Paste the following code into the General Declarations section of the DataReport:
Private Sub DataReport_Initialize() Dim mystr As String mystr = " Five Leading Spaces" & vbCrLf mystr = mystr & " Ten Leading Spaces" 'Uncomment this line to see the workaround. 'mystr = mystr & vbCrLf & String(10, 160) & "Ten Leading Spaces" MsgBox mystr Sections("Section1").Controls!label1.Caption = mystr End Sub
- Add a Label Control to the Detail section of the DataReport.
- Set the CanGrow property of the label to True.
- Set the BorderStyle property of the label to 1- rptBSSolid (this just makes it easier to see the problem).
- Add a Command button to Form1.
Paste the following code into the General Declarations section of the Form1:
Private Sub Command1_Click() DataReport1.Show End Sub
- Run the project and click the Command button. A message box shows you that the strings have multiple lines with leading spaces in each line. However, the label on the report shows that the leading spaces on the second line have been trimmed.
- Stop the project and uncomment the appropriate line of code in the DataReport_Initialize event.
- Run the project, click the Command button, and note that the label on the report shows that the line built with leading Chr(160) characters is not trimmed.
Keywords: kbdesigner kbprb KB248459