09-08-2025 09:41 PM
Hi, I am a new LabVIEW learner.
At the moment I get this error, and I don't know how to fix it, so can everyone help?
Here I try to connect the close file with the for loop, but it seems it cannot be connected. So what is the reason, and how can I connect it?
Thank you, guys.
Solved! Go to Solution.
09-09-2025 12:09 AM
Right-click on the tunnel, select Tunnel Mode >> Last Value
09-09-2025 12:40 AM
09-09-2025 07:09 AM
The reason for your error is because LabVIEw wires the output of a For loop as an array by default. So you're trying to connect the error cluster and the file refnum of the close file from an array of erros, and an array of Refnum.
What other suggested you to do, is to change the output of the for loop to one scalar, instead of array, either the last value or the option using shift register.
I agree with Gerd, shift register is a better option.
A shift register is a mechanism used in Labview to pass on values from one iteration to the next.
You create an shift register and start with values coming from outside the for loop. Then at each iteration, the same ref num or Error cluster will be "carried over' the next iteration, until the for loop ends and it goes to file close as scalar instead of array.
09-09-2025 07:19 AM - edited 09-09-2025 07:23 AM
Good morning, Justin.
As you can see, there are some "interesting" differences between how "output terminals" work for While Loops and For Loops. Why is that? How do you remember which is which? What's the "logic"? After all, both are "loops", designed to do some action repetitively until some "stop" condition is met.
Here's one way that I learned the difference. For Loops count things, and one of the prime "countable things" in LabVIEW is the Array. If you bring an Array into a For Loop, by design the input tunnel defaults to an Array tunnel (if you look closely, you'll see that inside the square box is a little pair of brackets, [ ], suggesting "elements of an Array"). Similarly, any wire you bring out of a For Loop will go out through an Array tunnel (trying bringing out the "Index" counter, [i], in the lower left corner). So if you need to bring out something that is not an Array (such as a reference wire), you need to right-click the output tunnel and change it to a "Last Value" tunnel, the solid square tunnel type.
The other thing to remember is that a While Loop always runs at least once, so any output tunnel will always have a value, but a For Loop might run 0 times (for example, you might pass in an empty Array), so if it has an output Array tunnel, it will also be empty, i.e. have no value. So if you bring in a Reference on a Value tunnel, and output it also on a Value tunnel, the output tunnel will not have a value and will either generate an error or cause a puzzle, "Why didn't my code work?". The Solution? Pass references on a Shift Register.
Bob Schor
P.S. -- for extra credit, what sort of tunnel should you use for the Error Line when using a For loop? I'm not sure I have a 100% certain answer to this, myself ...
09-09-2025 08:24 PM
Thank you for your clear explanation. Now I get it.