05-19-2011 06:38 AM
I have to write a program to generate random numbers till the Stop button is pressed, while saving the generated numbers. After the stop button is pressed, the largest of the generated Random numbers should be displayed
Solved! Go to Solution.
05-19-2011 06:50 AM - edited 05-19-2011 06:51 AM
Hi,
You may have a look at the attached VI. It does what you asked. It would benefit you if you go through the "Getting started with Labview" doccument before trying examples like this and posting doubts.
Regards,
Nitzz
(Give Kudos to good Answers, Mark as a solution if your problem is Solved;))
05-19-2011 06:57 AM
Thanks for the help, but there is one further issue. I will be using this as a part of another VI and i dont have to diplay the array of Random numbers. Will it be possible to remove it??
05-19-2011 07:03 AM
Hi,
If you dont want to display the array of random numbers just delete it and clean up the broken wires. It will work fine and give you the maximum values. To make it clear, the random numbers generated are not strored in the array indicator but it is stored in the shift register. So deleting the indicator wont do any harm.
Regards,
Nitzz
(Give Kudos to good Answers, Mark as a solution if your problem is Solved)
05-19-2011 07:12 AM - edited 05-19-2011 07:13 AM
Hi,
You may mark it as a solution if your problem is solved so that others may be benefitted.:)
Regards,
Nitzz
(Give Kudos to good Answers, Mark as a solution if your problem is Solved)
05-19-2011 07:20 AM
Guess it would be better if include the whole program..
i have this program, where when i press the start button it should generate of series of Random numbers and when the press the button marked as "Getpeak 1", it should get the meximum from the generated random numbers and calculate b1.
If the " Getpeak 1" is not pressed, the value of b1 stays as 1 and waits for the user to press "getpeak1"
05-19-2011 07:28 AM
Hi,
Check this example, It does what you need.
Regards,
Nitzz
(Give Kudos to good Answers, Mark as a solution if your problem is Solved)
05-19-2011 07:32 AM
Thanks... i was able to tweak my program with your random number example....
Can you please check if there are any bugs??... I noticed one though, the get peak button doesnt return to the False state after i stop the program
05-19-2011 07:32 AM
Thanks... i was able to tweak my program with your random number example....
Can you please check if there are any bugs??... I noticed one though, the get peak button doesnt return to the False state after i stop the program
05-19-2011 07:44 AM - edited 05-19-2011 07:45 AM
Hi,
There were some mistakes in your code. I have edited them and have attached here. Have a look.
Notes:
Always use a wait timer(wait till next ms) function inside a while loop if it is running for a long time. Otherwise the CPU usage will be very high.
When ever you build an array with build array in a loop, use a Shift Register. Otherwise only the last element will be built into the array and you will loose the rest of the elements.
Minimize the use of Local variables in your codes because they may create race conditions.
To turn back the state of any button after pressing it, Right click button -> properties -> operation -> Latch when pressed. This will turn on the button once and again will turn it off.
If you still have any doubts, feel free to post it here..:)
Regards,
Nitzz
(Give Kudos to good Answers, Mark as a solution if your problem is Solved)