LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help creating a few quick programs

Tells you how much I know about baseball 😄
 
(Most Europeans will share my ignorance ...).
0 Kudos
Message 11 of 29
(1,190 Views)

Wow,

That is really neat.  I never would have thought to do it that way. 

I started it by dividing the two and putting it through a integer case structure, but I never could figure out how to set the damn case structure up and get it to work.  For my own curiosity, which may also help for my last project, how would I setup a case structure if I took hits/bats outside of the case structure  put that value through the case structure then out of the case structure to display the outcome on a message?  I'm assuming I need to multiple the value by 1000 and divide on the outside, since the interger can't be decimal values.

I was thinking I could take an integer case structure using three scenerios one being if 0 then no at bats would be the result, if between 0 and .300 then keep swinging then greater then .300 potential hall of famer.  This seemed like an easier approach then what you submitted (I would have no way thought of setting it up that way, but i'm sure there are multiple ways of doing the same thing).

This is an interesting program as mentioned, I think this portion of the class, the few weeks that it was with little to no assistance is not very helpful.  It really needs to be taught with more instruction and on hands help. (the now, 20 total minutes of lecture time was taught/shown on a projector screen, no instruction help is/was given when we actually had the program in our hands).

Hopefully this will help me with the last project that is due...which I'm dreading.  You guys are more help then the professor.  All I asked from him was some sort of example that had similar properties to it...he never provided a damn thing.

Bob

 

0 Kudos
Message 12 of 29
(1,176 Views)
No, you should NOT divide outside the case structure, because if at-bats is zero, your result is undefined and cannot be used. You must ensure that the division only takes place if it results in a legal value.
 
I don't think you can get much simpler than my example. 🙂
0 Kudos
Message 13 of 29
(1,172 Views)

I certainly am not the expert as you are by any stretch of the imagination...lol.  How do you say in the case structure values up in the little box greater then something but less then something else?

Respectfully, It would seem that it would work. Once again, I’m not as knowledgeable as you are so i'll play the devils advocate...I just want to understand how these things work...lol  Your setup worked perfectly I just never would have thought to do it that way...I wish I did so I would have received more points for completing the problem.

 When I did it,  I called the default default value 0 to show "no at bats" and wired it to the outside of the case structure.  I had no idea how to set up the other part of the case structure.  I know that "..300" meant less then or equal to 300, and "300.." meant 300 or greater, I didn't now how to put the case structure so it said something like greater then 0 but less then 299 for the "keep practicing" and greater then 300 for potential hall of famer.  The reason why I used 300 is it needs an integer value...so no matter what the value is from the division outside the box, as long as it is multiplied by 1000 before the case structure it should work? 

Thanks for your comments!

Bob

 

0 Kudos
Message 14 of 29
(1,166 Views)
for what it's worth, the portion of no at bats did function correctly.  Where i'm going wrong is setting the damn case structure values in the little case structure box where you can choose various values.
 
Bob
0 Kudos
Message 15 of 29
(1,171 Views)


@bobl7777 wrote:

I certainly am not the expert as you are by any stretch of the imagination...lol.  How do you say in the case structure values up in the little box greater then something but less then something else?


You would say e.g. "1..299".


@bobl7777 wrote:

When I did it,  I called the default default value 0 to show "no at bats" and wired it to the outside of the case structure.  I had no idea how to set up the other part of the case structure. 



Beware of edge effects! For example of "hits=0", but "at-bats=20", you'll also get a zero. Your program would say "no at bats", which is incorrect in this situation. 😉 It is really not very useful to multiply with 1000 to do everything in integers, especially since the division will create a DBL again. (well, you could use Quotient&Remainder, but let's not complicate things further. You would still get the ambiguity between "no at bats" and "hits=0").
0 Kudos
Message 16 of 29
(1,160 Views)
"You would say e.g. "1..299"."
 
EXCELLENT...that's how you say between something...now that i look at it, that is simple.  I verified it and it worked fine.  When I chose as you mentioned, 0 hits and 20 at bats, it did say correctly "keep practicing"...which is what it should.
 
What I did was hits/batsx1000 went into the case structure, first default 0 case no at bats, second case 0..300, keep practicing, 300.., potential hall of famer. It worked though when I now chose 0 hits and 0 at bats, it was not displaying no at bats...everything else worked ok though.  When I changed the last case structure and limited to 300..1000, everything worked perfect. I didn't see anything bugs at all.  Should this not work or there be a flaw in somehting. 
 
I suppose one flaw I noticed was if I put 17 hits in it and 15 at bats, then it didn't display the correct statement...but it's impossible to hit more then what you were at bat.  How would I limit this?  I think with yours, if I did that, it just stayed at "future hall of famer" which is technically correct as I'm sure any baseball coach would love to have a baseball player whom could hit more then what he was at bat...lol 
 
I wish I could have understood this better before it was turned in!  I certainly would like to get the most points I can.  The rest of the course I have an A in, though the few weeks of labview, I don't think I have done as well as I could have.
 
 
0 Kudos
Message 17 of 29
(1,162 Views)


@bobl7777 wrote:
 
I suppose one flaw I noticed was if I put 17 hits in it and 15 at bats, then it didn't display the correct statement...but it's impossible to hit more then what you were at bat.  How would I limit this? 
Good. Now you're getting into progamming style. One of the most basic things in programming is making sure the user can't input invalid data and identifying errors. In this case there can be several solutions. For example, you can use a property node to limit the range of the numeric based on the number of hits, but then you force the user to set "hits" first, and that's not necessarily good. Another, simpler, alternative would be to add an external case structure which will check whether hits is equal to or smaller than at bats and if it isn't, wire the proper error message into the string.


___________________
Try to take over the world!
0 Kudos
Message 18 of 29
(1,149 Views)

"Another, simpler, alternative would be to add an external case structure which will check whether hits is equal to or smaller than at bats and if it isn't, wire the proper error message into the string."

 

Good point.  Ok just to test this out...I have attempted to do as you say though can't get that to work:-(.  I am unsure about a few things.  Actually, the sign that I woudl need is greater then (x>y) correct?  From what I understand, if x (hits) is greater then y (at bats), then the value is true, if not then false.  I was thinking to put it on the before the case structure, then run it into anohter...though that won't work.  I can state this out verbally, just not get it to work. 

My thoughts on how it should run "if hits >bats true then (new case structure) text to display "hits cannot be greater then at bats".  If hits > bats is false  then go through everything else as previously written.   Problem I see is how to wire up > sign.

Some help please:-).

0 Kudos
Message 19 of 29
(1,141 Views)

Well, you just wire the two inputs to the comparison operations. Now place a case structure around your existing case structure and wire the comparison output to the selector terminal.

One case will contain the old case structure and the other case will only contain a string diagram constant containing your error message. Both feed to the indicator. 


If you want to do the calculation using integers by multiplying the hits by 1000, you could also do something like in the attached example (labVIEW 7.0).

- Outer case checks for at-bats=0 as before.

- if at-bats is not zero (default) do the division and decide between three cases:

(1) 0..299         -> keep swinging
(2) 300..1000   -> potential hall ...
(3) Default:       -> Hits>at bats (result >1000)

This should take care of all possibilities. Notice that I use unsigned integers (U32) for the inputs so negative inputs cannot occur. Otherwise you would also need to check if the inputs are negative and create another error if this is the case.

0 Kudos
Message 20 of 29
(1,135 Views)