LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save the value from the case

Hello, I have a lot of random values and I want to specify a value with the push of a button. I used the case structure for this. But the value is only saved in the case and I cannot use the value outside of the case. How can I save the value?

 

Thank You 

0 Kudos
Message 1 of 9
(2,164 Views)

@Pantheraxxx wrote:

But the value is only saved in the case and I cannot use the value outside of the case. How can I save the value?


You just pass the value out of the case structure.  If you had a loop, I would say to use a Shift Register so you can reuse that value on the next iteration.  But with your small set of code, I'm not sure what you are trying to do.


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
0 Kudos
Message 2 of 9
(2,136 Views)

This is an little example from my Real Program. My job is to save one value from many different values with one button.

Can you show me how can i use the shift register for this programm? I dont understand it

 

thank you

0 Kudos
Message 3 of 9
(2,132 Views)

@Pantheraxxx wrote:

This is an little example from my Real Program. My job is to save one value from many different values with one button.

Can you show me how can i use the shift register for this programm? I dont understand it

 

thank you


I'm new myself but here are the resources I saved for shift registers.

 

here's some info on shift registers
https://www.ni.com/getting-started/labview-basics/shift-registers

and here is a decent (Though basic) video on them
https://www.youtube.com/watch?v=wkjcHispZNY

 

You'll also need to look up event structures, and auto indexing for loops (at least in my experience). I'm sure the others on here have more elegant solutions but that will get the job done. Experimenting with the different mechanical actions on the buttons won't hurt either.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.

I tried. I really did.
0 Kudos
Message 4 of 9
(2,098 Views)

Your question is not clear and your VI does not even have a toplevel loop.

You are using terms that are very ambiguous ("lots", "specify", "save", "push" (you have a switch with switch mechanical action, not a push button!))

 

You currently only generate exactly one random number, not "a lot".

Do you want to retain the last random numbers from separate runs, one for each boolean state? Do you want to maintain two evergrowing arrays of numbers?

 

If your real problem is to deal with lots of random values, then please attach a VI that simulates that. (And please don't maximize the front panel and diagram windows. It is extremely annoying to stare at a mostly white (or gray monitor) without the ability to look at other things, e.g. the help windows, which you definitely need!)

 

It is often easier to tell is what you want to do, not how you want to do it. My gut feeling is that you are currently barking up the wrong tree. How is the code used? What is the purpose? How does the user interact with the running program (And No, "run continuously" is not the way!). What should the user see in response to his actions? What should happen without user interaction? What is the loop rate?

Message 5 of 9
(2,070 Views)

@Pantheraxxx wrote:

Can you show me how can i use the shift register for this programm? I dont understand it


To use a shift register, you need a toplevel loop to anchor it. I typically prefer a feedback node, depending on the rest of the program architecture.

 

See this quick draft for some idea. (and no, to pick between two inputs, you don't need a case structure. A select keep all code in view for easier maintenance.).

 

 

altenbach_0-1626630414892.png

 

You need to decide how to initialize the feedback node, i.e. define what the value should be until the button is pressed for the first time. (NaN? Zero? First random value?, etc.)

 

Message 6 of 9
(2,063 Views)

@altenbach wrote:

@Pantheraxxx wrote:

Can you show me how can i use the shift register for this programm? I dont understand it


To use a shift register, you need a toplevel loop to anchor it. I typically prefer a feedback node, depending on the rest of the program architecture.

 

See this quick draft for some idea. (and no, to pick between two inputs, you don't need a case structure. A select keep all code in view for easier maintenance.).

 

 

altenbach_0-1626630414892.png

 

You need to decide how to initialize the feedback node, i.e. define what the value should be until the button is pressed for the first time. (NaN? Zero? First random value?, etc.)

 


That is absolutely beautiful code. Is it possible to put that in the "Example Code" section? It took me over an hour to solve this problem with my attached greenhorn code. I'm all about making the beginner materials better (especially since I practically live there these days). I'm willing to do legwork to make that happen.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.

I tried. I really did.
0 Kudos
Message 7 of 9
(2,052 Views)

Some comments on your code:

 

  • "OR FALSE" just retains the value of the other input, you can delete all that and just use a plain wire from dequeue to the case structure.
  • Your array never has more than one elements, so replace it with a scalar!
  • You inner FOR loop can be deleted because it only ever iterates exactly once. You currently use it as glorified "index array", which is not even needed if you just keep a scalar in the shift register.
  • If you use a timeout to wait at the dequeue operation, you don't really also need a wait in that loop.
  • Writing the value of the stop button to its own local variable is just plain silly! Place the terminal in the lower loop and connect it to the termination condition and output a TRUE constant from the stop event in the upper loop. No locals needed.
  • The "not case" does not need to go through the case structure, because the value is case invariant. (Well, the compiler will probably figure it out, but why complicate the code?).
  • You really don't need all these complications with two loops, events, queues, and such, especially since you need to poll the B control anyway. One loop is sufficient!
  • etc....
Message 8 of 9
(2,046 Views)

Thank you altenbach!


I'll be working through all those sugestions pointers things I need to learn, and studying your code. That's what I call paydirt. I'll make sure to pass on what I learn.


___________________________________________________________________________________________________________________________________________________
Upgraded from intern to undergrad automation engineer. Attempting to explain to my employer why I need official training…. since I’m the groups only automation engineer.

I tried. I really did.
0 Kudos
Message 9 of 9
(2,037 Views)