Thanks Chip,

Yes I generally don't like to short circuit functions especially in a loop I 
find that difficult to maintain.

My code is currently working except in the case where every item is checked and 
nothing was found. Is there a VB equivalent to  the Perl line:

return 0 unless  (  defined( MyVariable 

I might still add code to the test condition, but right now I am using two 
variables and two embedded loops  and I'll have to verify logic again.
)  ) )
Best wishes,

Jonathan



On Feb 15, 2014, at 5:09 PM, Chip Orange <lists3...@comcast.net> wrote:

> 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:jon.c.c...@gmail.com] 
> Sent: Saturday, February 15, 2014 2:47 PM
> To: gw-scripting@gwmicro.com
> 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 

Reply via email to