PRB: Run-time Error '6' When You Use the TextWidth Method (298825)
The information in this article applies to:
- Microsoft Visual Basic Enterprise Edition for Windows 4.0
- 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 4.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
- Microsoft Visual Basic Standard Edition for Windows 4.0
This article was previously published under Q298825 SYMPTOMS
When you use the TextWidth method on very large Strings, either a maximum value is returned, or the following error message is generated:
Run-time error '6':
Overflow
To determine which behavior is seen and at what String length it occurs, change the FontSize, FontName, or ScaleMode property.
RESOLUTION
To work around this problem, write a routine to recursively call TextWidth on smaller portions of the large String and return the sum. For example, you can call the following function instead of using TextWidth directly:
Function fTextWidth(sInString As String) As Long
If Len(sInString) > 500 Then
fTextWidth = Printer.TextWidth(Left(sInString, 500)) + _
fTextWidth(Right(sInString, Len(sInString) - 500))
Else
fTextWidth = fTextWidth + Printer.TextWidth(sInString)
End If
End Function
If you are not using TextWidth with the Printer object, substitute the correct object for Printer. This function handles large or small Strings without problems.
Modification Type: | Major | Last Reviewed: | 6/25/2004 |
---|
Keywords: | kbCodeSnippet kbFont kbnofix kbprb kbprint kbString KB298825 |
---|
|