Selecting delimited txt strings VB6

January 25, 2006 at 08:08:42
Specs: winxp pro, 800mhz Duron
I need help with selecting specific text in a richtextbox control in VB6.

What I originally wanted was a box with multiple paragraphs, each separated by two linefeed characters:

Dim strExample = "This is filler for the sake of this example, and serves to be nothing more than pretentious writing, solely for the purpose of being overly verbose and nonsensical; doing this proves to suit my purposes just fine." & vbCrLf & vbCrLf & _
"This second filler paragraph is to continue the train of thought with an unbroken, unfettered display of absolutely nothing, though slightly interesting and mildly entertaining nontheless."

RichTextBox1.Text = strExample

Now, I want to use the Click event to select all of the text in either of the two paragraphs, but not all text inside the entire richtextbox control:

Private Sub RichTextBox1_Click()
'not sure how to do it
'I was hoping someone would
'be able to help me
'thanks in advance
End Sub

Any ideas?
I have scoured the web for hours - and to no avail.


See More: Selecting delimited txt strings VB6

Report •


#1
January 25, 2006 at 09:29:03
Use the VBSplit function.

dim Ar() as string

Ar = Split(strExample, vbCr)

Ar is an undefined array. Split defines it filling each element of the array with text between each vbCRlf. In this example every other element in the array will contain a Null string because there are two successive delimiters with nothing between them.

If that is unacceptable then use the Instr in conjunction with the Mid$ function to search for each successive vbCrLf. That takes a little more coding.

Stuart


Report •

#2
January 25, 2006 at 09:55:44
StewartS,

Thanks again (you helped me before with the wininet.dll)

It works great -

Also, what I ended up doing was:

strDelimiters = vbCrLf & vbCrLf
Arr() = Split(strExample, strDelimiters)

...which gives me the two elements I originally wanted.

Thanks again!


Report •

#3
January 25, 2006 at 10:00:58
Oh, and by the way - here's another quick question:

How would I be able to click inside a richtextbox and select only a single paragraph in order to copy it to the clipboard?

I know I can drag the I-beam to select, but I want my prog to be more intuitive and easy to use.

I envision a richtextbox loaded with paragraphs and by clicking on one, it would be selected, leaving the rest unselected.

Is this an easy thing to impliment?


Report •

Related Solutions

#4
January 25, 2006 at 11:16:24
Good thinking Greg, putting the two CrLfs into a single string.

Selecting a whole paragraph with a single click could be a bit more difficult.

One way is to use the strings created with the Split function.

dim a as Integer
a = RTF1.Find(Arr(0), 0)

A will then contain the start location of the paragraph and the paragraph should be highlighted.


Stuart


Report •


Ask Question