Re: newbie: string handling question

Tech-Archive recommends: Fix windows errors by optimizing your registry



I didn't mean to imply your example was a bad coice ;-)...

The statement...

string02 = split(string01,",")(0)

....is one I would consider 100% bullet proof.

No matter what string01 contains (well, other that an object with no default
property returning a string, so make that 99.9% ;-), split will always
return at least an array with one element so the (0) index reference won't
fail. At worst, it simply returns the original string, as is.

On the other hand, if the logic assumed that there would be a (1) indexed
element, the bullet proof factor may drop to closer to 0.001% especially if
string01 is dynamic user input or some other unreliable or error prone
source!

My only point was that the use of compound/nested statements has to be very
carefully considered on a case by case basis or simply avoided as standard
procedure. An un-debuggable production problem certainly isn't worth saving
a few Dim's and separate statements.

--
Michael Harris
Microsoft MVP Scripting




.