Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

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
0
busycoder
Asked:
busycoder
  • 2
  • 2
  • 2
  • +1
3 Solutions
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
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
 
busycoderAuthor Commented:
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
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Olaf DoschkeSoftware DeveloperCommented:
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
 
pcelbaCommented:
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
 
pcelbaCommented:
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
 
busycoderAuthor Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now