From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing data to a string using case structures

Solved!
Go to solution

Hello Guys,

 

i' ll try my best to clearly explain my problem and code. I am reading a couple of RFID tags, either at the same time or 1 by 1. to do that i created a dummy array to compare my original array to determine weather a new tag was discovered or not. if it is discovered then i enter a description of it using a pop-up and i re-append the original array to the dummy one. My problem is writing the user input'ed data to a string array, now because of the case structures i have to write a value in the true AND false conditions. However, i do not need the false condition to write anything to my array. what can i do to have labview ignore that false case? and just write a value when the true case is indeed true?

I attached a snippet of my code, it has descriptions all over it, so it should be pretty clear.

 

Thank you in advance,

Fadi 

0 Kudos
Message 1 of 17
(3,807 Views)

Sorry for the first snippet, here is a better one.

 

Thanks

0 Kudos
Message 2 of 17
(3,804 Views)

Hi fadihajj,

 

My problem is writing the user input'ed data to a string array, now because of the case structures i have to write a value in the true AND false conditions. However, i do not need the false condition to write anything to my array. what can i do to have labview ignore that false case?

When you want to edit some data in one case of a case structure, but not in the other you should wire that data through the case structure…

check.png

 

General note:

When you want to collect data based on some kind of ID/"key" you should look for key/value-pair implementations. There is a simple one included in variants

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 17
(3,793 Views)

Thanks for replying quickly sir,

 

I know this, however this state is always running so it can check for tags. If tags are detected the user is prompted to enter a description of that tag. If not just repeat. So when a tag is NOT detected your method keeps adding the same data  over and over.

0 Kudos
Message 4 of 17
(3,779 Views)

Hi fadihajj,

 

So when a tag is NOT detected your method keeps adding the same data  over and over.

No, when the condition is not met then the data isn't altered at all…
Pseudocode:
IF condition THEN
  data := data +1
ELSE
  data := data
ENDIF
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 17
(3,775 Views)

Yes, very true. But when i am writing the output to the string array i am incrementing the index by 1 each iteration until the loop stops and i store that number in the cluster along with the array. That way i know where the last element was added. hence when the code processes the FALSE case it enters the for loop where data is written and keep adding those elements.

So i guess i need another condition to determine if the string remained the same or not. I was hoping this could be done in an easier way .

 

Thank you 

0 Kudos
Message 6 of 17
(3,766 Views)
Solution
Accepted by topic author fadihajj

Hello Fadihajj,

I checked your issue and I hope I understood your problem correctly.

 

I believe the problem is that you are wiring an empty array constant in the false condition. instead you can move the for loop that increments the index along with the bundle function inside the true case with after the "Sort Tag EPC" loop. This way the true case will get the user input and increment the index then bundle into cluster. For the false case, just wire the cluster coming from the left hand register of the while loop through the false case. This way the false condition, will pass the original cluster value unmodified. You will need to modify it in 2 locations for each Get User Input SubVI.

I hope this small modification fixes your issue.

 

 

Asser ElGindy
Applications Engineer (CLD)
National Instruments
Message 7 of 17
(3,713 Views)

Hello guys,

 

Sorry for the very late reply, i was super busy with other stuff.

It's kind of embarrassing how i never thought of doing what u suggested ASR.

Anyway, i went for a different approach, i am extracting all the data in an array of clusters and then i process each cluster.

I am going to accept your suggestion as a solution because it would have solved it.

 

Thanks guys and sorry again.

0 Kudos
Message 8 of 17
(3,662 Views)

Hello fadi,

Nice to know that your issue has been resolved. 

If you face any more issues please feel free to share them.

Asser ElGindy
Applications Engineer (CLD)
National Instruments
0 Kudos
Message 9 of 17
(3,653 Views)

Actually i am facing a problem, it is related to deleting rows from a text file.

If you can help me figure it out it would be awesome.

First i am writing the data that i acquired, but also i have a condition that determines if the array containing the removed elements is empty or not. If the array is empty nothing happens, if it isn't then i need to delete from the file the row(s) at the specified index/indices. in the attached code, the way this is working is its adding elements because the file size goes from 1kb to 200mb and this is where i am struggling. I know the write to file is in the while loop but it is deleting elements so the file shouldn't increase in size. As for the first write to file i tested it out before adding the other part and it was working as it should, it wrote exactly what is in the NSV.

0 Kudos
Message 10 of 17
(3,649 Views)