Solved

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

Posted on 2012-12-22
7
448 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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…
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

825 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