|
|
Title | Restrict a TextBox to at most four lines using the Change event |
Keywords | TextBox, restrict, lines, carriage return |
Categories | Controls |
|
|
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
|
|
|
|
|
|