Parsing a Value from a Multiline TextBox

G

Gordon Bentley-Mix

Word 2003

I have a UserForm with a multiline TextBox on it that allows the user to
enter several values separated by pressing the Enter key. (This wouldn't be
my preferred approach; I'd much rather collect each value separately and
load them into an array, but the users wouldn't be comfortable with this.)
In the document, I need this multiline value to be inserted in a location
that's formatted with a hanging indent - kind of like this:

[LABEL]: 1st Value
2nd Value
3rd Value
etc.

Of course, what happens is that each "value" from the multiline value is
inserted with a following hard return, which results in something like this:

[LABEL]: 1st Value
2nd Value
3rd Value
etc.

I've been experimenting with parsing the value from a multiline TextBox, and
it appears that the Enter key actually inserts two characters into the
value: a carriage return and a line feed (vbCr and vbLf). So entering
something like

1234<Enter>
6789<Enter>
1234

results in a value with a length of 16, the other four characters being two
pairs of vbCr / vbLf in place of the <Enters>. What I'd like to do is
replace these vbCr / vbLf pairs with a soft return [Chr(11)] so that the
value becomes something like:

1234[Chr(11)]6789[Chr(11)]1234

That way when the value is inserted into the document it honours the hanging
indent.

I reckon the best place to do this "replacement" is when I collect the
values from the UserForm. (The process I use extracts the various values
from the UserForm and stores them in variables before unloading the
UserForm. These variables are then used in the process for building the
document.) I envision having a "parsing function" that accepts arguments
that I can pass the value from the multiline TextBox into and get back a
clean value to store in the variable. However, I'm not quite sure what this
function would look like. I suppose it might involve the Mid function
somehow - since this is what I used to discover that the <Enters> were vbCr
/ vbLf pairs - and that I should probably start at the end of the value and
work backwards, but other than that...

Suggestions?
 

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