?
Solved

how many time the enter key press was pressed

Posted on 2008-10-30
5
Medium Priority
?
239 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:cano63
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 22846634
NumberLines = Len(txtInput) - Len(Replace(txtInput, vbCRLF, vbNullString)) / 2 + 1

Kevin
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 1000 total points
ID: 22846656
Correction:

NumberLines = (Len(txtInput) - Len(Replace(txtInput, vbCRLF, vbNullString))) / 2 + 1

Kevin
0
 
LVL 1

Author Comment

by:cano63
ID: 22846935
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
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 22846995
Not in VB6/VBA.

Kevin
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 22850207
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.
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

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question