Solved

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

Posted on 2003-11-11
5
152 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now