MaxLength Property for Visual Basic 6.0 Users
In Visual Basic 6.0, the MaxLength property of a TextBox control has absolute control over the length of a string that can be entered or displayed in the text box. Although you can programmatically enter a longer string, it is automatically truncated to the length set in the MaxLength property.
In Visual Basic 2008, the length of a string entered programmatically overrides the MaxLength property setting.
The following code illustrates the different behavior.
' Visual Basic 6.0 Text1.MaxLength = 5 Text1.Text = "Longer than five" MsgBox Text1.Text ' Displays "Longe".
What to do next
Review the design of your application to determine if the intended behavior was to always limit the text in the text box to the length set in the MaxLength property.
If this was the intended behavior, find each occurrence of code that sets the Text property, and add code to truncate the string, similar to the following example.
If it was not the intended behavior, leave the code alone. The user will still be limited by the MaxLength setting, but you can programmatically assign strings that are longer than the MaxLength setting.