11-10-2016 01:51 PM
Hello,
I am a student learning Labview. I am programming a Flashcard project for school. I have most of my code in place but am stuck on how to have 1 single random number be generated, and then wait for the user to enter a number in a numeric control before continuing on. I am supposed to use a sequence structure in the project. I need the user to see a set of 2 numbers to be either added, or multiplied. The user needs to then enter in their guess at the answer. The correct answer needs to be displayed, and then the loop starts over.
I am stuck on how to implement the random number function to only generate a single pair of numbers, and then have ther VI wait for the user input before continuing on. The answer should not be displayed until after the user has entered their guess.
I have included my VI so you can see where I'm at.
I appreciate any help or advice.
Thanks very much,
George
Solved! Go to Solution.
11-10-2016 02:06 PM
No need for a sequence structure. But you should look into a State Machine and the Event Structure.
11-10-2016 02:07 PM
Hi crossrulz,
Thanks for the reply. My Professor requires a sequence structure as part of the assignment.
Thanks!
George
11-10-2016 02:09 PM - edited 11-10-2016 02:12 PM
Hi George Spatta,
I am stuck on how to implement the random number function to only generate a single pair of numbers, and then have ther VI wait for the user input before continuing on. The answer should not be displayed until after the user has entered their guess.
Let me summarize your problem: you need a program that does step a, followed by step b, which enables step c.
To using "common wording": use a state machine!
On your current VI: what's the purpose of the sequence frame?
Why do you set the "answer" to be visible all the time?
Edit: I was a little bit slow - but now two (more experienced?) people advise to use the same pattern…
My Professor requires a sequence structure as part of the assignment.
Ask your professor about the purpose of that sequence. All it does is to enforce bad programming behaviour…
11-10-2016 02:20 PM
Hi GerdW,
Here is what I need to do. I'm sure there are better ways to do this practically, but these are the requirements I need to meet.
Thanks again!
George
11-10-2016 02:21 PM
I set the answer to be visible all the time so that while I was working out the rest of the code, I could see that the math functions were working properly.
Thanks,
George
11-10-2016 02:27 PM
Now that I think about it a little bit longer, the state machine really is not needed. You can do this easily with just a While loop and an Event Structure. Shift Registers will be needed. Still see no point in the Sequence Structure.
11-11-2016 01:38 AM
Hi,
reading your requirements I see no point telling you you have to do things in a special order. There is no indication you have to provide the correct answer AFTER the user has given his "guess" (why do we need to "guess" for simple math?)
This is a very poorly written requirement sheet!
11-11-2016 12:04 PM
Hi GerdW,
I completely agree with you. It does however make sense to me that you wouldn't want to see the correct answer until you've provided your guess. I also found out that you can't really wire the "Stop" button to the While Loop when using the Sequence Structure. I have put it in the last frame which will only allow the user to stop the VI within the 2 second window I have put in. I know that the example may not be a great one, but it was what I was tasked to do, and am doing the best I can. 🙂
Here is what I've come up with for a finished VI.
Again I appreciate all of the time & help / advice.
Thanks,
George
11-11-2016 02:41 PM
Why not put a Event Structure in the second frame of the sequence structure? I agree with Crossrulz and GerdW on this is not even practical and introduces bad LabVIEW programming habits, but wouldn't that work?