Hi Jonathan,
   This is what Chip means:

Function ReturnControl( Obj, MySearchItem)
 'Return A Control.
 Set ReturnControl = Nothing
 FOR EACH  oChild IN Obj.Children
  IF oChild.Name  = MySearchItem THEN
   Set ReturnControl = oChild
   EXIT Function
  End If
 END FOR
End Function

        Bruce

----- Original Message -----
From: "Chip Orange" <[email protected]>
To: <[email protected]>
Sent: Saturday, February 15, 2014 5:09 PM
Subject: RE: When a search fails how to handle.


Hi Jonathin,

First, you should not use the variable you are using to loop through your
collection, outside of the "for each" loop.  It's not defined to have any
value.   This is why you are sometimes getting an error in the line which
tries to use oChild.

I'd suggest before the "for each" loop, that you set the function's return
value to be "nothing"; so if you don't find it, this is what the function
will return.

Then, inside of the "if" inside the "for each", when you find the control,
set the function's return value to be what you found, and then have a "exit
function" command to stop searching.

There are other ways of doing this: set a variable to "nothing" before the
"for each" loop, and then set this variable to the found control if/when you
find it, and then have a "exit for" as you do.

After the loop, then set the function to return this variable.

It comes out to be about the same as my first suggestion, but maybe you find
it a little clearer.

Hth,

Chip


-----Original Message-----
From: Jonathan C. Cohn [mailto:[email protected]]
Sent: Saturday, February 15, 2014 2:47 PM
To: [email protected]
Subject: When a search fails how to handle.

Good day,

I have made progress in creating a script that searches for a given control.

FOR EACH  oChild IN Obj.Children
IF oChild.Name  = MySearchItem THEN
EXIT FOR
END FOR
' Nex line errors when search failed.
IF oChild
 IS  NOTHING THEN
ReturnValue = NOTHING
ELSE
ReturnValue = oChild
END IF

What should I be using in the second IF clause?

Thanks,

Jonathan


---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com

Reply via email to