LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with opening file with while loop

Solved!
Go to solution

It's because your file path is empty going into the first read from spreadsheet function at the "top" and the scond one in the "middle." You're not understanding basic dataflow. Dataflow means something will execute when all inputs are available to it. Look at your "middle" read from file. All inputs are available to it as soon as you press start. Both the "top" read from spreadsheet file and "middle" are executing in parallel with a blank path as an input. What you need is to wire the output from the "top" read from spreadsheet into the "middle" read from spreadhseet, just like you did from the "middle" to the "bottom" read from spreadsheet. But, as I said earlier, you really don't need to do this eventhough it will work. You only need to and only should read the file one time. Also, you didn't notice that I said my "array subset" function had the index from the search1d array wired up wrong. You copied my solution exactly, but didn't count for this mistake I mentioned Smiley Wink

 

But, an even better suggestion is to take the LabVIEW tutorials because you are not understanding basic concepts; you are not quite understanding dataflow. These are basic concepts that you need to understanding, or you are going to keep running into walls like this.

 

I could post a solution for you, but I am going to ask you to see if you can understand why this is happening. You will be better off if you have a "eureka" moment, so I encourage you to try one or two more times. We've all been there Smiley Happy

Message 11 of 23
(1,520 Views)

I should also throw in the fact that you don't need the sequence structure or your two local variables.  You can use wires instead.

 

I'm also lost as to why the while loop.  Nothing is changing, so just run the code once.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 12 of 23
(1,504 Views)

Greg,

 

   Ok, couple things.

 

   1.) Thanks for the pointers and tips. Much appreciated.

   2.) I figured out how to "fix" the problem in my original program via creating a feedback node. Now I know that's not the optimum case as it's in a while loop, but I am still learning.

    3.) That being said, I looked more closely at your solution and while I do understand dataflow much better (via tutorials, but still not an expert), I still have a question because I'd like to learn. I get what Search1D array is doing, but I would think the output from that would be wired to length (not index as we had it before), but two things I notice (and I do have an indicator to state this) - it doesn't find "endheader" in the file, it cuts off right before it, and I thought that the length would also allow populate the listboxes, which they do not.

 

     Any further hints would be appreciated as I would like to understand where I am going right/wrong. That's the only way I'm going to get better. I need to break down the fear of LabVIEW that I've always had unfortunately.

 

    Thanks!

    TheLT

0 Kudos
Message 13 of 23
(1,476 Views)

@TheLT wrote:

Greg,

 

   2.) I figured out how to "fix" the problem in my original program via creating a feedback node. Now I know that's not the optimum case as it's in a while loop, but I am still learning.

    3.) That being said, I looked more closely at your solution and while I do understand dataflow much better (via tutorials, but still not an expert), I still have a question because I'd like to learn. I get what Search1D array is doing, but I would think the output from that would be wired to length (not index as we had it before), but two things I notice (and I do have an indicator to state this) - it doesn't find "endheader" in the file, it cuts off right before it, and I thought that the length would also allow populate the listboxes, which they do not.

 

     Any further hints would be appreciated as I would like to understand where I am going right/wrong. That's the only way I'm going to get better. I need to break down the fear of LabVIEW that I've always had unfortunately.

 

    Thanks!

    TheLT


First off, you don't need a feedback node. You need the value coming out of the file path output just like you did between the second and third file reads. You just need to do that same things between the first and the second (if you're determined to continue using 3 file reads. 

You're correct about the index supposed to be wired to the length. Did you read my posts closely? I admitted this mistake in two of my posts, and also wrote what you needed to do to correct it. I just didn't want to remake the VI and take another screenshot to repost. You've attempted a lot so I'll see if I can point you in the right direction with a more refined solution and maybe it will help you understand. I'm somewhat of a "have to see it before I get it" kind of person so to some extent I get where you're coming from.

Message 14 of 23
(1,472 Views)
Solution
Accepted by topic author TheLT

See the attached image. It has comments explaining everything I did. I may have been able to simplify it with fewer array functions, but by breaking it out I think it will help you to better understand the steps I am taking to make this work. I just posted an image so you can still code it up yourself, and as you code it more stuff may click. You may want to put some of that stuff in a subVI called something like "Parse file" to help redability and maintainance. I just didn't do this so you could see all the code in the image.

 

Message 15 of 23
(1,467 Views)

Greg,

 

  Thanks for your post - wow I follow what you are doing now. And I also see an event structure. Slick.Smiley LOL

 

   About the feedback node, ok assume for a second that we strictly had to keep the while loop in there (how I did it in the beginning) - I did use a feedback node, and I thought you needed that if you are going to solely use a while loop, then you'd have to use that, but you're saying otherwise.

   Can you please explain before I mark this off? I'm just trying to be a better LabVIEWer. Maybe one day I can go after being a CLA!

 

   Thanks!

    TheLT

0 Kudos
Message 16 of 23
(1,441 Views)

necesito ayuda.

 

 

1º ¿ como puedo hacer que lo datos que tengo y qiero guardar en un archivo no me pida la " ruta" es decir donde quiero guardarlos cada vez que ejecuto el programa y llega a ese punto? yo qiero que me guarde los datos cuadno llege a ese punto pero automáticamente sin que cada vez que yege me pida la ruta para guardar.

 

2º quiero leer un arxivo .txt y que cuyos valores me los introduzca en una "tabla"  el problema que se plantea esque esos valores si que los lee y los representa xro me los pone en cualquier fila del documento .txt y yo lo que quiero es que me los vaya guardando desde la primera fila hasta las ultimas no donde le apetezca 

 

alguien me puede ayudar xfavor.

muchas gracias

0 Kudos
Message 17 of 23
(1,432 Views)

Roo,

 

   Lo siento, pero mi espanol es muy roto. Por favor habla en ingles?

 

     Gracias!

     TheLT

0 Kudos
Message 18 of 23
(1,411 Views)

@TheLT wrote:

Greg,

 

  Thanks for your post - wow I follow what you are doing now. And I also see an event structure. Slick.Smiley LOL

 

   About the feedback node, ok assume for a second that we strictly had to keep the while loop in there (how I did it in the beginning) - I did use a feedback node, and I thought you needed that if you are going to solely use a while loop, then you'd have to use that, but you're saying otherwise.

   Can you please explain before I mark this off? I'm just trying to be a better LabVIEWer. Maybe one day I can go after being a CLA!

 

   Thanks!

    TheLT


So, the reason the feedback node is an issue is not that there is fundamentally a problem with reading a file using a feedback node to specify the starting read position, and reading in chunks. In fact, I believe there is a point where the file size is large enough that it's more efficient to read in chunks rather than read the whole file with a single call (notice, I said I believe, and I'm not entirely sure about this).

 

But, the issue is with the way teh read from spreadsheet file itself is coded. If you look inside the read from spreadsheet file, there is an open file, a read file, and a close file. The issue with using this read from spreadsheet function in a loop is that it is continually opening and closing the file with each loop iteration.  These are operations you don't want to perform repeatedly. If you need to read a file in chunks, you would open it outside the loop, do the "read" inside the loop, then close the file once when the loop finishes (i.e. outside the loop). Does this make sense? This way you open the file once, and close the file once; the only thing you are doing multiple times is calling the read function.

Message 19 of 23
(1,388 Views)

Greg,

 

There definitely is a point where it becomes necessary to read in chunks.  I recently was processing text-based spreadsheet files of >100MB and having both string and numeric arrays in memory at the same time created memory problems.  By reading in chunks I was able to get the memory footprint to a few percent above the final numeric array size.

 

Lynn

0 Kudos
Message 20 of 23
(1,383 Views)