04-13-2016 03:55 PM - last edited on 04-14-2016 12:07 PM by LiliMcDonald
I have a FOR loop within which I want to use a 1D array of boolean outputs from a comparison. There is a one-to-one correspondence between FOR loop index and array index, so the loop count and the array size are the same. I first tried using the Insert Into Array function, which worked fine except that the array kept growing in size. Once I understood this, I replaced it with the Replace Array Subset function, which seemed to be more appropriate. However, it doesn't work: nothing ever appears in the array. I tried it using numbers instead of boolean values, as an experiment, but that didn't work either. I'm at a loss as to what I'm doing wrong or not understanding and would appreciate suggestions. I've attached an image of the relevant portion of the VI.
Thanks,
Scott
Admin note - Attachment removed per user's request - 04/14/16
Solved! Go to Solution.
04-13-2016 04:08 PM
Please do not attach pictures of code, attach the code (translation -- attach the VI itself). It is difficult to execute a JPeg, let alone to see the entire Block Diagram ...
Bob Schor
04-13-2016 04:09 PM
The shift register for your array is unitialized and therefore empty. You can not replace an elmenent that does not exist so the array remains empty. You need to initialize an array before the loop with the proper size and wire it to the shift register.
04-13-2016 04:11 PM
The VI won't run without the associated hardware (motor, DAQ modules, power supply, etc.), so posting the VI itself won't do any good. I was hoping that there would be something obvious just by looking at the image, or perhaps I'm not understanding how the function works, despite reading the Help for it?
Scott
04-13-2016 04:13 PM
To Darin: that's interesting, I'll have to try that. Why wasn't that a problem when I was using the Insert function?
Thanks,
Scott
04-13-2016 04:20 PM
You can insert into an empty array no problem. What will be a problem is that the array will continue to grow each time you run the program.
04-13-2016 04:22 PM
I see. Okay, I will see if it works. I wish the Help page gave a hint about this!
Thanks,
Scott
04-13-2016 08:16 PM
For future reference, it's generally trivial to simulate a DAQ device. With the way you code, it's much more difficult to take a look at what's going on. Even if we ignore the case structure inside of a while loop instead of a for loop (yikes), we see you have tunnels all around the structures leaving us to guess what's taking place. Sometimes, what you're doing wrong may be so obvious it's easy to see. Other times, where these are coming from changes everything.
You should break yourself of several of those habits ASAP. The first, inputs come in on the left. Outputs leave on the right. That habit makes your code worlds easier to read.
Second, whatever logic you're running, there is certainly an easier way than 3 deep structures. Don't overcomplicate things.
The Help file is taking some common sense into consideration. You cannot reasonably replace what doesn't exist. If help documentation called out every possible thing that couldn't happen, it'd be a nasty mess of the 800000 corner cases that could take place. It'd be anything but help. You can figure out a lot of these things by using the debugging tools. Probes or highlight execution would have shown you what was happening in this case.
04-13-2016 09:07 PM
@scottbbb wrote:... so posting the VI itself won't do any good.
We can't tell anything from the image, because we don't know what's in the other cases of the case structure (maybe the boolean array gets initialized to a finite size elsewhere in a previous iteration!). We don't see what outside the visible area you deemed "relevant". Other parts might be relevant too to us! Code does not need to runnable to be analyzed by us for problems.
It is also offensive to post 5+MB photograph with over 4000 pixels horizontally, i.e. with many more pixels that contained on a typical monitor.
Many mobile users have plans with data limits and posting 5+MB for a few kB if information is not nice at all.
Do you know how to take a screenshot without a camera? It's very simple!
You should also try to read the help on format statements. A format of %3.3f does not break anything, buth makes logically very little sense. I assume that the code contains many more such surprises.
04-13-2016 10:24 PM - edited 04-13-2016 10:33 PM
Wow, I seem to have stirred up a few hornets' nests! I certainly didn't intend to offend anyone with my poor code-writing and forum-posting practices. I'm a novice and don't know any better -- just trying to get a quick-and-dirty project done so I can go back to my regular work, which does not involve LabVIEW.
I've asked the moderators to remove my originial post so that the large image in it doesn't affect anyone else.
Scott