Solved

How can I retreive (and select) ONLY the top line in a rich text edit box?

Posted on 2012-12-22
7
435 Views
Last Modified: 2013-01-10
In a regular edit box you can just use mline, but this does not seem to work in a rich text edit box accurately, due to non fixed width line of text (of course). I need to do a line by line scan based on only what is in shown in the window in a rich text edit box control on a form.

I tried setting the position in the RTF box then using KEYBOARD '{SHIFT + END}', but windows 7 has issues with this I think, and I would like to do this a better way anyway.

So in short I need a guaranteed way to retrieve only the first line of text in a rich text edit box, then only the second, then third etc.

Thanks again in advance!!

BC
0
Comment
Question by:busycoder
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 38715999
Please define the first line. If it's surrounded by delimiters then you can use the Search or Find word. Can you use Non-Wrap?

We need more information to help you. Can you post a sample?
0
 

Author Comment

by:busycoder
ID: 38716045
It won't be surrounded by delimiters. I can't have the user doing that kind of work

On a form place a rich text edit box, with a paragraph of text in it, then retreive the text line by line as you see it visually. This is what I want to do.
0
 
LVL 27

Assisted Solution

by:CaptainCyril
CaptainCyril earned 50 total points
ID: 38716122
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 100 total points
ID: 38716872
The question is, what you want to achieve on a larger scale?

Eg, the detail problem of finding out the single lines may be part of a solution to print RTF as show in the RTFEditbox, and the solution may be much simpler than trying to figure out the single lines and putting them in a memo to print, but simply put an RTF control with the right dimensions into an FRX.

Here is a similar problem about finding out a line number http://www.daniweb.com/software-development/visual-basic-4-5-6/threads/413375/selecting-entire-linerow-in-richtextbox#

It points to some details of interest for your problem, if you really want to stay with solving it instead of replanning on the larger scale. In short: It's comlicated.

Helpful properties are rtfbox.Multiline, if that is .F. you can simply do ALINES on the RTF full text and will have the text lines. If it's .T. you have automatic line breaks and then SelStart, SelLength and rtfbox.GetLineFromChar() can help you find out how far you have to go into the left and right direction from a current cursor position to catch that current line, and The first line of course always starts at SelStart=0 (or 1, but you'll figure that out, if 0 is not allowed) and SelLength=0 puts the cursor right at the beginning. Now you could loop until rtfbox.GetLineFromChar() returns the next line, then take one step back and you have the first line.

I'm not able to do that for you right now, as I am at Win7 without the RTF control and I think you can aim at your problem with this info on your own, now.

Bye, Olaf.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 38716949
To retrieve the top line in RTF box control is relatively easy:
*-- Method GetRTF1stLine
LPARAMETERS loRTF

LOCAL lnI, lcRetVal
lcRetVal = loRTF.text

FOR lnI = 1 TO LEN(m.lcRetVal)
  IF loRTF.GetLineFromChar(m.lnI) > 0
    lcRetVal = LEFT(m.lcRetVal, m.lnI)
    EXIT
  ENDIF
NEXT

WAIT WINDOW m.lcRetVal

RETURN m.lcRetVal

Open in new window

Calling sample:
THISFORM.GetRTF1stLine(THISFORM.RTFControl)

To retrieve other lines just needs a small update:
LPARAMETERS loRTF, lnLine

IF lnLine < 1
  RETURN ''
ENDIF

LOCAL lnI, lcRetVal, lnStartPos
lcRetVal = ''
lnStartPos = LEN(loRTF.text) + 1

FOR lnI = 1 TO LEN(loRTF.text)
  IF loRTF.GetLineFromChar(m.lnI) >= m.lnLine - 1
    lnStartPos = m.lnI
    lcRetVal = SUBSTR(loRTF.text, m.lnStartPos)
    EXIT
  ENDIF
NEXT

FOR lnI = m.lnStartPos+1 TO LEN(loRTF.text)
  IF loRTF.GetLineFromChar(m.lnI) > m.lnLine - 1
    lcRetVal = LEFT(m.lcRetVal, m.lnI-m.lnStartPos+1)
    loRtf.SelStart = m.lnStartPos-1
    loRtf.SelLength = m.lnI-m.lnStartPos+1
    EXIT
  ENDIF
NEXT

WAIT WINDOW m.lcRetVal

RETURN m.lcRetVal

Open in new window


You may optimize the code for additional lines by passing the character position on which the GetLineFromChar should start.
0
 
LVL 41

Accepted Solution

by:
pcelba earned 350 total points
ID: 38716968
Code to retrieve and select given line revised:
LPARAMETERS loRTF, lnLine

IF lnLine < 1
  RETURN ''
ENDIF

LOCAL lnI, lcRetVal, lnStartPos
lcRetVal = ''
lnStartPos = LEN(loRTF.text) + 1

FOR lnI = 0 TO LEN(loRTF.text)
  IF loRTF.GetLineFromChar(m.lnI) > m.lnLine - 2
    lnStartPos = m.lnI
    lcRetVal = SUBSTR(loRTF.text, m.lnStartPos+1)
    EXIT
  ENDIF
NEXT

FOR lnI = m.lnStartPos+1 TO LEN(loRTF.text)
  IF loRTF.GetLineFromChar(m.lnI) > m.lnLine - 1
    lcRetVal = LEFT(m.lcRetVal, m.lnI-m.lnStartPos)
    loRtf.SelStart = m.lnStartPos
    loRtf.SelLength = m.lnI-m.lnStartPos
    EXIT
  ENDIF
NEXT

WAIT WINDOW m.lcRetVal

RETURN m.lcRetVal

Open in new window

0
 

Author Closing Comment

by:busycoder
ID: 38764700
This was a super big help everyone!!! I really appreciate this, I was able to work on a different part of this project, and then this was just in time to finish it up. I owe you all lunch again!!!!<br /><br />-BC
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

12 Experts available now in Live!

Get 1:1 Help Now