cano63
asked on
how many time the enter key press was pressed
I have a Textbox that is a multiline, i want to limit the user so he can press the enter key just10 times. my idea is that the multiline textbox don,t have more than 10 lines. is there any function for that ? any idea
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
IS there any other Way
i know vbcrfl give the 13 and 10 that are enter , are a way that i can use it to know what i,m looking
Your example work fine,
is there something like this
x = text1.vbcrfl
i know vbcrfl give the 13 and 10 that are enter , are a way that i can use it to know what i,m looking
Your example work fine,
is there something like this
x = text1.vbcrfl
Not in VB6/VBA.
Kevin
Kevin
I would suggest something like tracking how many times the enter key has been pressed with the KeyPress event. But the flaw in any plan like that is the fact that the user can copy and paste text into the TextBox, and that text could have more than 10 lines in it.
So zorvek is steering you in the right direction, at least in concept.
What you really might have to do is that on the CHANGE event, drop all text that occurs after the 10th CrLf. See if the following code snippet won't do all you're looking for.
Note the extra code of tracking SelStart is needed because the current selection point jumps if text is added that results in text getting chopped off.
So zorvek is steering you in the right direction, at least in concept.
What you really might have to do is that on the CHANGE event, drop all text that occurs after the 10th CrLf. See if the following code snippet won't do all you're looking for.
Note the extra code of tracking SelStart is needed because the current selection point jumps if text is added that results in text getting chopped off.
Private Sub Text1_Change()
Dim MyText As String
Dim Start As Long
Dim Pos As Long
Dim Count As Long
Dim SelStart As Long
Dim SelLen As Long
SelStart = Text1.SelStart
SelLen = Text1.SelLength
MyText = Text1.Text
Count = 0
Start = 1
Pos = InStr(Start, MyText, vbCrLf)
Do While Pos
Count = Count + 1
If Count = 10 Then
Text1.Text = Left$(MyText, Pos - 1)
If SelLen = 0 Then
Text1.SelStart = SelStart
End If
Exit Do
End If
Start = Pos + 2
Pos = InStr(Start, MyText, vbCrLf)
Loop
End Sub
Kevin