Avatar of busycoder
busycoder
 asked on

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

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
FoxPro

Avatar of undefined
Last Comment
busycoder

8/22/2022 - Mon
Cyril Joudieh

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?
busycoder

ASKER
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.
SOLUTION
Cyril Joudieh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Olaf Doschke

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Pavel Celba

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Pavel Celba

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
busycoder

ASKER
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