AnsweredAssumed Answered

Re2: VRF-Checking if a number is contained within an array

Question asked by VRFuser on Mar 16, 1998
All,
        I use the method described below often, however there is one
     caveat.  I use gate objects to feed the signals into the control pins,
     with the gates' sequence pins connected and the sequence out of the
     last gate into the seq in of the LIST BOX.  The caveat is that if the
     "DEFAULT VALUE" is NOT in the ENUM LIST, an error will be generated. 
     If you add an ERROR OUTPUT to the LIST BOX, it will NOT trap this
     error.  My solution has been to build all of these objects (the GATES
     and the LIST BOX) into a USER OBJECT and then add an ERROR OUTPUT pin
     to the USER OBJECT.  This ERROR pin will trap the error and you can
     handle the failed match appropriately. 
        I use this frequently to match an input against a list of possible
     options and will use the Ordinal of the selection to index into the
     original options array (frequently an array of records defining the
     option).  This method is MUCH faster than looping through a list of
     possibilities to find a match.  There is one other thing to be aware
     of - if there are two entries in the ENUM LIST with the same value,
     the selection will match the FIRST entry in the list, so each entry
     must be a unique value.
    
     Thomas Groleau
     Tucson, Arizona


______________________________ Reply Separator _________________________________
Subject: Re: VRF-Checking if a number is contained within an array ..
Author:  "Greg E Noseworthy" <greg.noseworthy@comdev.ca> at CCGATE
Date:    3/17/98 6:35 AM


There is one way, however, it can be tricky.  If you use the selection control
items (ie. list, cyclic button, etc.), you can put control inputs to the
object.  The two that you would be interested in would be the Default Value
and the Enum Value.
    
The tricky part comes when you try to run it.  Because these are control
inputs, the list will execute before the control inputs are activated...  or
rather, it will execute first, using whatever value was last on the control
inputs.
    
I tried this, and had to tie the flow controls together to make sure that the
list got executed after the search array and the search value.  It worked
really well, and even returned the index.
    
James Atkin wrote:
    
> Is there a function to check if a number is part of an array of x numbers.
> i.e. Is the number 3 contained within an array of 10 integers ?
>
> Thanks
>
> James
>
> (James.Atkin@Phase.Com)
    
    
    


Outcomes