Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

679 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