LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

HELP I'M NEW TO CODING BUT HAVE A PROJECT (BASIC)

I'm trying to build a code for a project. It's very simple. 

 

I need to use either a random number generator which generates numbers 1 to 3 or I need to be able to enter a number in.  Depending on whether the number is 1, 2, or 3, will determine what will happen.

 

For number 1, a green light will go on and a dialogue box with pre-entered text will pop up.

 

For number 2, a green light and red light will go on as well as another dialogue box with pre-entered text.

 

For number 3, a green light, red light, and two different dialogue boxes will pop up.

 

I really need help fast.. Thank you! 🙂

0 Kudos
Message 1 of 15
(3,710 Views)

This is a simple application of a case structure.  What specific part are you having trouble with?  What have you tried so far?  

 

We are not here to do your work for you, especially since this sounds like homework.  Post a VI of what you have attempted and ask specific questions about the sections of code you are having problems with.

0 Kudos
Message 2 of 15
(3,704 Views)
I'm in a design class and my project is pretty much an alert system. I was planning on using a case structure and I had attached a numeric control/indicator to it. I put a random number generator on that, but it only gives me numbers 0-1 and I don't know if or how to change that. I guess I'm kind of confused on how a case structure works. Thanks.
0 Kudos
Message 3 of 15
(3,698 Views)

That's not a LabVIEW question anymore, but a math question.  Generating random numbers is something that should be taught in any basic programming class.

 

The random number generator gives a number from 0 to 1.  Zero is part of the data set, 1 is not.  So 0  to  0.999999999..

 

You want a range of 1, 2, 3 integers only.

 

Multiply by 3.  Now you'll have a number from 0 to 2.999999 ....

Add 1,  Now you'll have a number from 1 to 3.99999999....

Round down towards -infinity  Now you'll have 1, 2, or 3.

 

 

 

Message 4 of 15
(3,691 Views)

Take the random number function, multiply it by 2, round the result to the nearest whole number.  That will give you 0-2.  Then add 1 to get 1-3.  Pass the resulting number to your case selector.

0 Kudos
Message 5 of 15
(3,690 Views)

@Thomas_robertson wrote:

Take the random number function, multiply it by 2, round the result to the nearest whole number.  That will give you 0-2.  Then add 1 to get 1-3.  Pass the resulting number to your case selector.


Wrong.  You do not round to nearest.  That only gives you half the probability for the numbers at the end of the range.

 

Multiply by 3 and round down.

Message 6 of 15
(3,673 Views)
Okay I'm just going to use a numeric control and put whatever number I want. Can you explain the case structure to me?
0 Kudos
Message 7 of 15
(3,671 Views)

Wire the numeric control to the case structure control terminal (the green ? mark).  Make a case for the numbers 1, 2, and 3.  "if you are asking for these explanations you should really really really take the time to go through the LabVIEW CORE traning)  It should only take a couple hours.

0 Kudos
Message 8 of 15
(3,661 Views)

Help -> Show context help.

 

Drop a case structure on the block diagram and hover mouse over it. The context help window displays a brief summary plus a link to detailed help text. Click the link,

 

You will find the LabView help system gives you answers much faster than a forum will, especially considering the general nature of your question. If you get stuck, come back with some code and a specific question. Its amazing what you will find out if you just look.

0 Kudos
Message 9 of 15
(3,659 Views)

Good point.   I'll bet I coded some randomize routines wrong in the past...  So round down is always the right thing to do.  NI should revamp the random number function such that you can type in a range.

0 Kudos
Message 10 of 15
(3,629 Views)