Home
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleRestrict a TextBox to at most four lines using the Change event
KeywordsTextBox, restrict, lines, carriage return
CategoriesControls
 
In the Change event handler, examine the TextBox's new value. If it is valid, save the new value in a static variable. If the value is invalid, restore the previously saved value.
 
Private Sub Text1_Change()
Static old_value As String

    ' See how many carriage returns the value has.
    ' Note that Split returns a zero-based array
    ' so UBound gives 1 less than the number of items.
    ' Restore the old value.
    If UBound(Split(Text1.Text, vbCr)) > 2 Then
        ' More than 3 carriage returns so
        ' more than 4 lines.
        Text1.Text = old_value
    Else
        ' No more than 3 carriage returns so
        ' no more than 4 lines. Save the new value.
        old_value = Text1.Text
    End If
End Sub
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated