Array of booleans

I have an array of booleans defined as follows:-
Boolean [] isComplete = new Boolean[noOfBooleans];What I am trying to do is to continue a loop till all the values of this array are set to true. What I have tried is
do {
    for (int i = 0; i < isComplete.length; i++) {
        if(isComplete) {
break;
}while(true);
but it would break if anyof these booleans is true and I am not sure how to put an && condition in there. Any help would be great.
Edited by: LisaM on Nov 10, 2009 11:26 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

LisaM wrote:
^you are right, actually I am dealing with threads here, what I am trying to do is to start a number of independant threads, and as these threads complete set the isComplete boolean to true. But I am unable to check when all the threads have finished. If you want to wait for the thread to complete, as opposed to just knowing when they complete, use Thread.join:
List<Thread> threadList = new ArrayList<Thread>();
for (...) {
  Thread th = new Thread(...);
  th.start();
  threadList.add(th);
for (Thread th : threadList) {
  th.join();
// when we get here, all the threads we started are doneAs for your code, if you do decide to continue with your initial approach (fixing the code so it actually works, of course), I have a few suggestions.
1. A busy-wait loop like that will kill performance. Use wait/notify or sleep so that test loop doesn't eat up all your CPU.
2. You'll have to synchronize all access to the array, otherwise the testing thread may never see the writing threads' updates.
3. You may want to use BitSet instead of an array. It seems a little cleaner to me, but it won't make any real difference. You'll still have to sync all access to it.
Finally, depending one what you're really trying to do, you may find some of the tools in the java.util.concurrent packages easier to work with than this low-level threading stuff.

Similar Messages

  • How can I change the properties of only one element in an array of booleans?

    I'm displaying an array of booleans to my operators, with each boolean in the array representing some system status check.  Some of these checks are critical and some are not, therefore I want some of these booleans to have a different color when in the TRUE state (Red for the critical ones and Yellow for the non-critical ones).  I can change the boolean colors with a property node, but that effects every element in the array.  Is there any way to change a property of an individual element in an array?  I know that I could take the incoming array and break it into two arrays - one for critical and one for non-critical, but this system is replacing an older system and the operators are accustomed to seeing their indicator lights a certain way and I'm trying to replicate what they had exactly.

    Here's what I had in mind
    Of course you can use as many colors as you want.
    Message Edited by altenbach on 12-21-2005 04:53 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    LEDarray.png ‏7 KB
    ColorArray3.vi ‏23 KB

  • Can I Bind a Front Panel LED to a specific element in an array of booleans?

    In LabVIEW 2010 I have a string of LEDs. I have and array of boolean values that contain the values that the LEDs should indicate.
    What is the best way to connect the LEDs to elements in the array of booleans?
    Can I Bind a Front Panel LED to a specific element in an array of booleans?
    How is this done?
    Can anyone show sample code?
    Solved!
    Go to Solution.

    Imagine that you have an I/O card that provides 128, 256 or 1024 digital inputs and the requirement is to have an LED on the front panel to represent the state of each digital input. This frequently occurs.
    Wiring that many digital inputs individually is a royal pain and then some !
    It would make sense to have one shared variable as an array of Booleans that represents the status of all inputs and then use data binding instead of wiring each individually. The individually wiring would violate all recommendations on diagram size and fan out.
    Frequently scanned For loops to update all of the LEDS would take alot of CPU time.
    Wouldn't it be MUCH better if PSP could be used to update the LEDs whenever the data changed (as it is supposed to do) ?
    In my case I have a LabVIEW Yaskawa servo driver that provides me information about 16 servo drives that may be connected. I have LEDs on the front panel to represent some of that status for each individual drive. But Yaskawa provides the information on the drives as an array of clusters of information for each drive, which I perform some business logic on and turn into shared array of Booleans to feed the LEDs (and some banks of switches as well).
    Unfortunately LabVIEW does not seem to have any way to bind the LEDs (and Switches) to individual elements in the shared array of Booleans. It is just not that smart. Even with only several banks of 16 LEDs and Switches, wiring them individually using Decimate Array of Index Array functions is a royal pain and makes the block diagrams very large. It would be much worse and almost unreasonable to do if the size of the information was much larger.

  • Is there an example vi for converting an array of boolean to list an array of Int based on a selected T/F state?

    I would like to use arrays to minimize code.
    I am trying to generate an array of int base on an array of boolean randomly selected.

    You can try using 'Boolean to 0,1.vi', found in the Boolean palette: this vi converts a scalar, array or cluster of booleans to a scalar, array or cluster of word (I16 integers).
    To use it, simply wire an array of booleans (indicator) to its left, and an array of integers (control) to its right et voilà.
    Roberto
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Converting a string of numbers into an array of booleans

    For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?

    billko wrote:
    Hooovahh wrote:
    billko wrote:
    Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier. 
    I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.
    LOL maybe that was one of the objectives of the homework. 
    To be fair it sounds like there is more work that is needed.  A new user of LabVIEW will have a hard time figuring out how to process each character one at a time when it isn't in an array.  
    It's just that most people (me at least) stopped thinking about division with quotient and remainder after basic algebra.  I then of course changed my way of thinking when I used LabVIEW.  Still most of the time when you use division you want to know the fractional part as a decimal.  Thinking this way makes the problem more difficult then it needs to be.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How to create a grid with arrays and booleans?

    As part of a bigger project, I'm trying to create a sub-VI which will allow me to move a "cursor" in a 3x3 array.
    There should be 2 boolean inputs, one for moving down in the array, and the other for moving to the right. Once the edge of the array has been reached, the "cursor" will start back from the beginning.
    I have a vague idea of a 2 dimensional array with LED's. Once "down" has been pressed, the LED corresponding to (0,0) will turn off, turning (0,1) on. Same goes for the "right" button. When "down" is pressed at (0,2), the LED should turn off, and LED (0,0) should turn on.
    I'm sure it has something to do with initializing arrays, but i can't seem to find the right way to do it.
    Any kind of assistance is much appreciated. Thanks!
    Solved!
    Go to Solution.

    Maybe this will help.
    Oh, I just noticed that I could have done the "Clear True" outside of the inner case structure and some other things too, but oh well - it works.
    Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
    question. Give "Kudos" to replies that help.
    Attachments:
    grid_png.vi ‏14 KB

  • Array of Boolean to String

    Hello All,
    I have a small coding challenge that has been whipping me all day.   I have a 19 element boolean array that I would like to convert to a string without delimiters("0000000000000000000").    Within a for loop I use a "Select" followed by a "Number To Decimal String."   Once outside the loop then use the "Array To Spreadsheet String" function on the indexed output.    I tried using a blank delimiter input on the "Array To Spreadsheet String" function but that reverts back to tabs.   Bummer.   I'll keep plugging away trying different functions and constructs, but this feels harder than it really should be.    Any fresh prespectives would be greatly appreciated!
    Sincerely,
    Zach
    Solved!
    Go to Solution.
    Attachments:
    array_of_clusters_to_XLS (SubVI).vi ‏31 KB

    super-neuron wrote:
      I have a 19 element boolean array that I would like to convert to a string without delimiters("0000000000000000000").
    "Boolean to 0,1" - > "Number to decimal string" -> "concatenate array". No loop needed.
    EDIT: looks like smercurio beat me to it.
    Message Edited by altenbach on 08-05-2008 02:09 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    BooleanArrayToText.vi ‏8 KB
    BooleanArrayToText.png ‏9 KB

  • Boolean text property in array of booleans

    I am having difficutly in creating a simple program that creates an array of clusters of boolean controls where each boolean has its own custom text.  I attempt to auto create the boolean text in a loop and then after writing to change each individual control, I bundle it and collect it into an array.  What am I doing wrong here?  
    Solved!
    Go to Solution.
    Attachments:
    Boolean text Issue.vi ‏9 KB

    Where's your cluster?
    All elements of an array must have the same properties.  This includes the boolean text.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Efficient Int32 Array to Boolean Array to Int16 Array

    Have a large array of Int32 (~500,000 elements).
    Each Int32 needs to be parsed into two Int16 arrays: Array 1 is the first 12 bits of the Int32, Array 2 is the second 12 bits of the Int32.
    The method I am using (see attached) works just fine but it is taking a lot of time to run (on a relatively slow, embedded CPU).
    Does anyone have an idea how to make this run faster?
    Solved!
    Go to Solution.
    Attachments:
    Example Code.rtf ‏571 KB

    Red Sox Fanatic wrote:
    Excellent - thanks I'll give it a try!
    Not that you needed more ways to solve this problem, but lots of us on this board are curious about performance and I had a few minutes to throw together a VI to test the timing of a few approaches suggested here, as well as two variations of an additional approach that I like (shown here).  The basic conclusion is that they're all pretty close on my machine (LV 2009).  Splitting a 1-million element array, averaged over 50 times, the approach with 2 ANDs was 20ms.  Using a FOR loop was 21ms.  Using a pair of shifts (shown below) was 17ms.  A variation of this, with a typecast, was much slower, at 35.5ms.
    Attachments:
    2x12 bits from 32.vi ‏19 KB

  • Boolean Array-- Help Plz Urgent

    Can i create and initialize an array of booleans like this ?
    Boolean[51] Position = true;
    Thanks... Plz help

    This works:Boolean[] bools = {
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true), new Boolean(true),
        new Boolean(true), new Boolean(true), new Boolean(true)
    };... and, fortunately, so does this:Boolean[] bools = new Boolean[51];
    java.util.Arrays.fill(bools, new Boolean(true));I hope you find this of some help.

  • How to change names of an Boolean array in a which has been placed in a cluster?

    Hi guys,
    for my program i need to initialize which tests are in a testblock. Each test is settable with a Booelan button to enable the test, or disable it.
    I have actually 22 testblocks containg over 400 tests. What i would like to do is to make 1 array  with Boolean buttons. So, if you're exploring the testblocks, the labels of this buttons must contain the test names. How can i make a program so the testnames will be automatically transferred to the label of the Boolean buttons? (My array of buttons is placed in a cluster, because i have more data to store about the tests..)
    thanx for your help.
    Attachments:
    example.JPG ‏207 KB

    Hi btwesseli...,
    in an array all elements have the same properties. So you cannot make the labels/captions or whatever different for those booleans.
    But:
    You can overlay an string over the boolean button. Make a string indicator your cluster, make this string transparent and move it over the boolean. Now you can have a
    'label' over the boolean containing the name of the test.
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Store boolean array as text file

    Hi there
    I'm having some trouble storinge a 25x25 2D array of booleans in a text file.
    First I make the 2D array a 1D array, and then I change it to a number, but here something already goes wrong, not the full number is stored, presumably because the array is this big?
    Any help will be much appreciated!
    Solved!
    Go to Solution.
    Attachments:
    Store 2D boolean array LV10.vi ‏17 KB

    You can also convert the 2D boolean array into 1D array of numbers and save to text file and then read back to load the original 2D Boolean array
    The best solution is the one you find it by yourself
    Attachments:
    2D Boolean to String.vi ‏16 KB

  • How do I return a Boolean array from LabView to TestStand?

    I am trying to return a Boolean array from Labview to TestStand and have TS evaluate the results. I can do this for arrays of integers or reals but booleans do not work. I tried copying the PassFailTest step type and adding an array of Bool but I couldn't get it to evaluate the array. It simply always passed. How can this be done?
    Bob A.

    I have thought about evaluating the Boolean data in TestStand but, as you say, this is a lot of work. What I have been doing is to map the boolean data to integers in LV (very easy) and then use the multiple numeric step type to evaluate the integer array automatically. This feels kludgy and I have tried a couple of times to create a "multiple boolean" step type with little success. I'm surprised TS hasn't anticipated a test returning multiple pass/fail results. I do this all the time for production code.
    What I have tried is to copy MultipleNumericLimitsTest data type to a custom type and add a BooleanArray with a data type Array of Boolean[0..empty]. Then when I specify module, I select Step.BooleanArray as the value. The last step (that I know of) is to select Step.BooleanArray as the data source in the edit limits window. At this point if I run the test, I get the error "expect numeric, found boolean" (or something similar). When I look at the properties of my custom step type, the Substeps has DoMultiNumericMeasEvaluation as the Post-Step. I believe this is the root of my problem but I can't figure out how to change this to "DoMultiBooleanMeasEvaluation" or similar. Any Ideas?

  • Element position in boolean array

    Hi,
    I have a boolean array, whose elements are initialized to false. For example,
    private boolean array[] = new boolean[10];Later on I set an element of the array to true. Let's say
    array[5] = true;My question is how can I get the integer position of the element whose value(s) is/are true? Is there a method that does this? I looked into Arrays class but couldn't find anything.
    Thanks in advance.

    blias wrote:
    I have a boolean array, whose elements are initialized to false...
    My question is how can I get the integer position of the element whose value(s) is/are true? Is there a method that does this? I looked into Arrays class but couldn't find anything.You might want to have a look at [url http://download.oracle.com/javase/6/docs/api/java/util/BitSet.html]BitSet. It has loads of stuff for doing anything your heart desires for a bunch of bits, including Boolean operations on combinations and what you want.
    Winston

  • Boolean array to number

    I'm not sure if this has ever been brought up before, but if so, here it is again.  Lets say I have a Boolean Array shown with 8 elements arranged horizontally.  When I read it, I usually read left to right, meaning the MSB is on the left and the LSB is on the right.  However, if I use the Boolean Array to Number funtion, this function reads right to left.  Same for the Number to Boolean Array function,  It will form the array from right to left.  This goes against normal boolean reading habits.  I know this isn't a bug because it was probably meant to operate as such.  The VI shown below illustrates what I mean.  Three questions:
    Why is it done this way?
    Why not make the functions configurable to read in either direction?
    The term Big Endian / Little Endian applies to byte order in a 16-bit word broken into two bytes.  Does it also apply to bit order in a U8?
    Here is the VI:
    - tbob
    Inventor of the WORM Global
    Solved!
    Go to Solution.
    Attachments:
    BoolArrayToNumber.vi ‏10 KB

    tbob wrote:
    Why is it done this way?
    Why not make the functions configurable to read in either direction?
    The term Big Endian / Little Endian applies to byte order in a 16-bit word broken into two bytes.  Does it also apply to bit order in a U8?
    Bit ordering is (almost) always consistent.  The lowest order bit is bit 0.  In LabVIEW's array representation, index 0 is on the left, so you see it what you consider to be "backwards."  If this were changed, or configurable, it would be confusing when you feed only a few bits of an array into boolean array to numeric.  I expect that if I build two TRUE values into an array and then convert that to a numeric, that those two TRUE values will be in the low-order bits and the rest will be padded with zeros; anything else would puzzle me.

Maybe you are looking for