Finding blank lines in a multi-line text box

S

Silvester

Hi,

How can I find the positions of every blank line in my multi-line A2000 form
text box linked to a table memo field.

I've figured out how to get the total number of characters and lines in the
box but this one is foxing me as it's too late and the grey matter is
shutting down.

eg:
Baa Baa
Black Sheep
Have you any wool

Yes Sir
Yes Sir
etc

Yes Sir
Yes Sir
etc

TIA
 
K

Ken Snell

By blank line, do you mean the presence only of the carriage return and line
feed characters? If yes, you can do a search for doubles of the combination
of these characters:

LocationInString = InStr(Me.TextBoxName.Value, Chr(13) & Chr(10) & Chr(13) &
Chr(10)) + 2

Something like the above may work for you.
 
S

Silvester

Thanks Ken,

Actually I meant any/all blank lines between 2 lines of text. So its a
little more tricky than just searching for vbnewline.

Any ideas ?
 
K

Ken Snell

What do you want to "return" when you find a blank line (is a blank line the
absence of characters, or the presence of one/more space characters with no
other characters)?
 
J

John Spencer (MVP)

Ken, Silvester,

Pardon me for jumping in but ...

Ok, define blank line (no characters other than crlf - carriage return, line
feed - or no visible characters - a string of spaces)) and define position
(character number; line number as defined by crlf, or line number as defined by
wraparound or crlf).

IF you want the "line number as defined by crlf", you might try using the split
function to break the memo field into an array based on vbcrlf and then check
the array's cells to see if the trimmed value is zero-length, then you could
return the array cell number(s) as a result of the function.

That said then what do you want the function to return.
 
S

Silvester

Thanks Ken and John,

I finally figured it out and developed it from there. The jist is to:

'start the split
vParagraphs = Split(Me.MemoBox, vbCrLf)
i = 0

For Each vPara In vParagraphs
vLines = Split(vPara, vbnewline)
'MsgBox vPara
MyArray(i) = vPara
i = i + 1
Next

I then trap the newlines from the array and reassemble the paragraph
allowing only single blank lines and adding my own delimiters.

Thanks very much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top