LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array has same elements

Solved!
Go to solution

Hello,

 

I am trying to add a piece of data from a Json string which I have parsed successfully. Howhen When I try to put the data in an Arry using for loop, the built array gives all elements as the same number.

 

I have been trying to fix this since two days and have also gone through many threads but could not get help.

 

The o/p arrays looks like

 

layman93_0-1588118908424.png

My VI for array looks like this.

 

layman93_1-1588118991854.png

I have tried working with Auto indexing as well as shift register, but nothing seems to work. Iit will be really helpful if someone can guide me through it.

 

Thanks

 

 

 

0 Kudos
Message 1 of 11
(6,395 Views)

Your for loop input has only one value. How are you expecting to get different values ever?

 

Maybe you want to build the array in a shift register anchored on the toplevel while loop?

 

(It's is hard to give more target advice if you only show us a tiny piece of a diagram picture. Attach your VI! )

Message 2 of 11
(6,378 Views)

The problem is that your data changes outside the loop.  The loop will only grab the data from there once, and work with that value.  The thing that changes the values has to be inside your loop.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 11
(6,374 Views)

If you want something to change inside a loop, you'll have to change it inside a loop ...

In pseudo code, you're writing:

array y

int x = 3370

for (i=0;i<4000;i++)

{

  y.add(x)

}

 

Now what would be added to the array y?

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 11
(6,302 Views)

Hello,

 

Thank you all for the prompt response.

 

Here is the attached VI. I am trying to build an array with data from my Json string.

 

 

 

 

0 Kudos
Message 5 of 11
(6,275 Views)
Solution
Accepted by topic author layman93

Maybe something like that?

 

Of course of you want to only keep the latest 500, you need a little more code. Currently, you will eventually run out of memory if the array grows without bounds.

 

altenbach_0-1588177387989.png

You would do something similar th the entry ID (not shown)

 

You might even want to bundle the ID and value into a cluster and create an array of clusters.

 

Your string parsing looks a bit convoluted. Do you have an example string? Looks like you dealing with time quanta (hours, minutes, seonds, etc.), so why is there orange? Aren't these integers?I am sure there is a much simpler way.

Message 6 of 11
(6,258 Views)

Hello Altenbach, 

 

Let me try with the feedback node.

 

This is my Json string (

 https://api.thingspeak.com/channels/1038537/feeds.json?api_key=S2Z7WRAMR790XII5&results=2

which I have parsed. I had to extract all the values from the string and then convert them into numeric. 

 

I am sure there is a very simple way but I am very new to Labview and could just build whatever i got from the forums.

 

Thanks for the example, let me try and get back here.

 

Thanks

0 Kudos
Message 7 of 11
(6,247 Views)

The feedback element works perfectly the way I want it. Thank you Altenbach.

0 Kudos
Message 8 of 11
(6,245 Views)

Here's how to parse the time string.

  • Top: your code
  • Bottom: my alternative. Arguably simpler! (For more complicated case, use a more specific time format, check the help)

 

altenbach_1-1588182545320.png

 

 

 

Message 9 of 11
(6,234 Views)

This is really simple actually.

 

I tried with scan from string function and asked it to scan timestamp, but as you may have noticed the time stamp had zone and time separator, due to which it never worked for me.

 

But your solution is brilliant, thank you so much.

0 Kudos
Message 10 of 11
(6,226 Views)