Solved

how do i restrict user not to type more than 5 lines in RTFBox

Posted on 2003-11-11
5
156 Views
Last Modified: 2010-05-03
how do i restrict user not to type more than 5 lines in RTFBox. I am using SendMessage API method (in keypress event), which returns me nos. of line but when i press any key at the end of fifth line, it wrap the last word on sixth line, this is only the problem, otherwise it works fine.

It is very urgent, any help, idea, or clue will be highly obliged. Thanks in advance.
0
Comment
Question by:nirmal_4194
[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
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9721673
Does
Keyascii = 0
not work (as in a standard textbox?)
0
 

Author Comment

by:nirmal_4194
ID: 9738183
Yes it works, but by the time the last word jumps to 6th line.

Can you give me coding which you have tested.

Thanks for response.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9738687
Good point.

This is tested:

Private Sub RTB_Change()
    Do While RTB.GetLineFromChar(Len(RTB.Text)) > 5
        RTB.Text = Left$(RTB.Text, Len(RTB.Text) - 1)
    Loop
End Sub

It needs a loop, because if the user enters a wide character not at the end of the fifth line, then more than one narrow character might be displaced on to the next line.
0
 

Author Comment

by:nirmal_4194
ID: 9873044
No it does not work. Please test it again, i am desparately need help.

Thanks for quick response
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 20 total points
ID: 9873286
I can find an error, but it is a simple one. The line numbers returned by the function GetLineFromChar() start at 0, so that line number 5 is actually the 6th line.
If you change the 5 to a 4, it will work,  limiting the entry to 5 lines rather than 6 lines, as my original code does.
Because this was so simple, it may be that I haven't understood the problem that you were having with the code. If so can you explain what happens?
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

688 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