Link to home
Start Free TrialLog in
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
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

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?
Avatar of busycoder
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
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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