ArrayArrayArrayArrayArray BrainModular BrainModular Users Forum 2017-11-26T13:28:15+02:00 https://brainmodular.com/forums/app.php/feed/topic/5985 2017-11-26T13:28:15+02:00 2017-11-26T13:28:15+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38593#p38593 <![CDATA['Check for Value in Array' script not working]]> I'll take a look.
But here is a workaround :

CODE:

////////////////////////////////////////////////////// Check if a value is in the array/////////////////////////////////////////////////////var Arr, Found, Valsearch &#58; Tparameter;Procedure Init;BEGIN  Arr        &#58;= CreateParam&#40;'ArrayIn',PtArray&#41;;                   setisOutput&#40;Arr,false&#41;;  ValSearch  &#58;= CreateParam&#40;'Value to search',PtDataField&#41;;  setisOutput&#40;Valsearch,false&#41;; setvalue&#40;valsearch,1&#41;;  Found      &#58;= CreateParam&#40;'value found',PtSwitch&#41;;         setisInput&#40;Found,false&#41;;END;//////////////////////////////////////////////////////////////////////Procedure Callback &#40;n&#58; integer&#41;;            // Scan the N inputs, and n pick the index of any input that changed to                                            // return result in same bloc.var valFound &#58; boolean;                     // "is our value found?" is a boolean = binary choice TRUE or FALSE type                                            // of variablevar i &#58; integer;                            // integer used to scan thru the array elements.BEGIN                                       // Start the callback = check inputs changesIF &#40;n=Arr&#41; then begin                      // if changes on Arr input, start   i &#58;= 0;                                  // reset i &#40;=index to scan&#41;   valfound&#58;=FALSE;                         // by default the value is not found   while &#40;&#40;not valFound&#41;    and &#40;i < GetLength&#40;arr&#41;&#41;&#41;    do begin           // do the check for each elmt among array                                                                      // length as long as value isn't found             if &#40;GetDataArrayValue&#40;arr, i&#41; = getvalue&#40;Valsearch&#41; &#41;      then valFound &#58;= TRUE;// boolean result of the check we want to do ,//      if valfound then itrace&#40;i&#41;;                                                                // TRUE if the array elmt&#40;i&#41; = our input value      i &#58;= i + 1;                                                     // increment the scanned elmt          end;   if valfound then begin                    //if the result of valfound is true, we set parameter to 1      setvalue&#40;Found,1&#41;;   end   else begin                            //otherwise we set it to 0;      setvalue&#40;Found,0&#41;;        end; END;  //end of subchec   end;

Statistics: Posted by senso — 26 Nov 2017, 12:28


]]>
2017-11-26T06:57:13+02:00 2017-11-26T06:57:13+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38591#p38591 <![CDATA['Check for Value in Array' script not working]]> Statistics: Posted by CREDO — 26 Nov 2017, 05:57


]]>
2017-11-25T06:55:56+02:00 2017-11-25T06:55:56+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38588#p38588 <![CDATA['Check for Value in Array' script not working]]> Statistics: Posted by CREDO — 25 Nov 2017, 05:55


]]>
2017-11-25T05:37:10+02:00 2017-11-25T05:37:10+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38587#p38587 <![CDATA['Check for Value in Array' script not working]]> what value are you searching?

Statistics: Posted by 23fx23 — 25 Nov 2017, 04:37


]]>
2017-11-24T23:50:30+02:00 2017-11-24T23:50:30+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38584#p38584 <![CDATA['Check for Value in Array' script not working]]> (I am VERY new to attempting anything with scripts, so any insight would be greatly appreciated!)

////////////////////////////////////////////////////
// Check if a value is in the array
/////////////////////////////////////////////////////
var Arr, Found, Valsearch : Tparameter;

Procedure Init;
BEGIN
Arr := CreateParam('ArrayIn',PtArray);
setisOutput(Arr,false);
ValSearch := CreateParam('Value to search',PtDataField);
setisOutput(Valsearch,false); setvalue(valsearch,1);
Found := CreateParam('value found',PtSwitch);
setisInput(Found,false);
END;
//////////////////////////////////////////////////////////////////////
Procedure Callback (n: integer); // Scan the N inputs, and n pick the index of any input that changed to
// return result in same bloc.
var valFound : boolean; // "is our value found?" is a boolean = binary choice TRUE or FALSE type
// of variable
var i : integer; // integer used to scan thru the array elements.
BEGIN // Start the callback = check inputs changes

IF (n=Arr) then begin // if changes on Arr input, start
i := 0; // reset i (=index to scan)
valfound:=FALSE; // by default the value is not found
while ((not valFound) and (i < GetLength(arr))) do begin // do the check for each elmt among array
// length as long as value isn't found
valFound := (GetDataArrayValue(arr, i) = getvalue(Valsearch) ); // boolean result of the check we want to do ,
// TRUE if the array elmt(i) = our input value
i := i + 1; // increment the scanned elmt
end;
if valfound then begin //if the result of valfound is true, we set parameter to 1
setvalue(Found,1);
end
else begin //otherwise we set it to 0;
setvalue(Found,0);
end;
END; //end of subcheck process
END; // END of callback

Statistics: Posted by CREDO — 24 Nov 2017, 22:50


]]>
BrainModular BrainModular Users Forum 2017-11-26T13:28:15+02:00 https://brainmodular.com/forums/app.php/feed/topic/5985 2017-11-26T13:28:15+02:00 2017-11-26T13:28:15+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38593#p38593 <![CDATA['Check for Value in Array' script not working]]> I'll take a look.
But here is a workaround :

CODE:

////////////////////////////////////////////////////// Check if a value is in the array/////////////////////////////////////////////////////var Arr, Found, Valsearch &#58; Tparameter;Procedure Init;BEGIN  Arr        &#58;= CreateParam&#40;'ArrayIn',PtArray&#41;;                   setisOutput&#40;Arr,false&#41;;  ValSearch  &#58;= CreateParam&#40;'Value to search',PtDataField&#41;;  setisOutput&#40;Valsearch,false&#41;; setvalue&#40;valsearch,1&#41;;  Found      &#58;= CreateParam&#40;'value found',PtSwitch&#41;;         setisInput&#40;Found,false&#41;;END;//////////////////////////////////////////////////////////////////////Procedure Callback &#40;n&#58; integer&#41;;            // Scan the N inputs, and n pick the index of any input that changed to                                            // return result in same bloc.var valFound &#58; boolean;                     // "is our value found?" is a boolean = binary choice TRUE or FALSE type                                            // of variablevar i &#58; integer;                            // integer used to scan thru the array elements.BEGIN                                       // Start the callback = check inputs changesIF &#40;n=Arr&#41; then begin                      // if changes on Arr input, start   i &#58;= 0;                                  // reset i &#40;=index to scan&#41;   valfound&#58;=FALSE;                         // by default the value is not found   while &#40;&#40;not valFound&#41;    and &#40;i < GetLength&#40;arr&#41;&#41;&#41;    do begin           // do the check for each elmt among array                                                                      // length as long as value isn't found             if &#40;GetDataArrayValue&#40;arr, i&#41; = getvalue&#40;Valsearch&#41; &#41;      then valFound &#58;= TRUE;// boolean result of the check we want to do ,//      if valfound then itrace&#40;i&#41;;                                                                // TRUE if the array elmt&#40;i&#41; = our input value      i &#58;= i + 1;                                                     // increment the scanned elmt          end;   if valfound then begin                    //if the result of valfound is true, we set parameter to 1      setvalue&#40;Found,1&#41;;   end   else begin                            //otherwise we set it to 0;      setvalue&#40;Found,0&#41;;        end; END;  //end of subchec   end;

Statistics: Posted by senso — 26 Nov 2017, 12:28


]]>
2017-11-26T06:57:13+02:00 2017-11-26T06:57:13+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38591#p38591 <![CDATA['Check for Value in Array' script not working]]> Statistics: Posted by CREDO — 26 Nov 2017, 05:57


]]>
2017-11-25T06:55:56+02:00 2017-11-25T06:55:56+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38588#p38588 <![CDATA['Check for Value in Array' script not working]]> Statistics: Posted by CREDO — 25 Nov 2017, 05:55


]]>
2017-11-25T05:37:10+02:00 2017-11-25T05:37:10+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38587#p38587 <![CDATA['Check for Value in Array' script not working]]> what value are you searching?

Statistics: Posted by 23fx23 — 25 Nov 2017, 04:37


]]>
2017-11-24T23:50:30+02:00 2017-11-24T23:50:30+02:00 https://brainmodular.com/forums/viewtopic.php?t=5985&p=38584#p38584 <![CDATA['Check for Value in Array' script not working]]> (I am VERY new to attempting anything with scripts, so any insight would be greatly appreciated!)

////////////////////////////////////////////////////
// Check if a value is in the array
/////////////////////////////////////////////////////
var Arr, Found, Valsearch : Tparameter;

Procedure Init;
BEGIN
Arr := CreateParam('ArrayIn',PtArray);
setisOutput(Arr,false);
ValSearch := CreateParam('Value to search',PtDataField);
setisOutput(Valsearch,false); setvalue(valsearch,1);
Found := CreateParam('value found',PtSwitch);
setisInput(Found,false);
END;
//////////////////////////////////////////////////////////////////////
Procedure Callback (n: integer); // Scan the N inputs, and n pick the index of any input that changed to
// return result in same bloc.
var valFound : boolean; // "is our value found?" is a boolean = binary choice TRUE or FALSE type
// of variable
var i : integer; // integer used to scan thru the array elements.
BEGIN // Start the callback = check inputs changes

IF (n=Arr) then begin // if changes on Arr input, start
i := 0; // reset i (=index to scan)
valfound:=FALSE; // by default the value is not found
while ((not valFound) and (i < GetLength(arr))) do begin // do the check for each elmt among array
// length as long as value isn't found
valFound := (GetDataArrayValue(arr, i) = getvalue(Valsearch) ); // boolean result of the check we want to do ,
// TRUE if the array elmt(i) = our input value
i := i + 1; // increment the scanned elmt
end;
if valfound then begin //if the result of valfound is true, we set parameter to 1
setvalue(Found,1);
end
else begin //otherwise we set it to 0;
setvalue(Found,0);
end;
END; //end of subcheck process
END; // END of callback

Statistics: Posted by CREDO — 24 Nov 2017, 22:50


]]>