Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

759 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

26 Experts available now in Live!

Get 1:1 Help Now