Rick Rothstein submitted this idea :
I always think of it as String function work with the actual characters
themselves... the first character is position 1... whereas the Selxxx
functions work with the positions between the characters. Just to be clear
about this, the "Sel" in the various Selxxx commands is short for "selection"
(referring to selected text). Picture in your mind some selected
characters... they are highlighted and SelStart and SelLength are used in
code to do the selecting of those characters. Let's work with one character
because it is easy to picture, so SelLength is 1 (but SelLength could be more
which just means more characters are selected). Picturing the selected
character, think where SelStart must be... yep, it is located to the left of
the character that was selected... it acts as the anchor point for the
selection... the highlight starts from the SelStart position immediately to
the left of the selected character and a SelLength of 1 says starting from
that SelStart position, sweep across one character and highlight it. So, to
select the first character, SelStart, the anchor point is located before that
first character, at position 0 (it really has to be 0 because I think things
would break down at the end of the text if it were 1). I don't know if the
above is clear or not, but I think if you keep in mind that the Sel part of
the command is short for "selection", it might help.
Rick Rothstein (MVP - Excel)
"GS" wrote in message ...
It happens that Rick Rothstein formulated :
Try 'SelStart = 1' since 1 is the position of the first character.
No, Garry, 0 is the correct starting point for SelStart... SelStart is the
location of the caret (text cursor) and its starting position is before the
first character which is indexed for it at 0. The help file for SelStart
sort of addresses this in the description section for the Long argument.
Rick Rothstein (MVP - Excel)
Thanks, Rick!
This has always been confusing for me to get right, causing me to
always paly around with it to get the correct result. Your explanation
of the relationship between the caret position and the starting point
clears this up. If I've finally captured the gist of it then starting
point is BEFORE the left side of a particular character position (0
being before 1); start position as used in InStr, for example, is to
the left of the specified character position, based on the 1st
character being 1.
Thanks again, Rick. Not sure if your extended explanation is any more
helpful than the first. I've more or less concluded that the Sel????
functions work with the position BEFORE the character whereas the
String functions work with the position the character is AT in the
string.
The part about Sel meaning 'selection' has always been there for me and
so the position part was what I got confused with. I think it's mostly
because I use the String functions way more than Sel???? and so I've
made a mental "i before e except after c" type of rule: "sel BEFORE pos
AT"!
--
Garry
Free usenet access at
http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc