LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Empty String Control when other is filled (Pythagorean Theorem)

Solved!
Go to solution

I want to be able to calculate the side of any right triangle and be able to clear out the controls if all are filled. I have done this but with my code, I have to run the program again to clear it. I know I could set it so all fields are cleared by pressing a button, but is there a way to do it without pressing one?

 

Also is there a way to clear one of the controls if the other 2 are filled?

p.theorem block.pngPy.theorem block.png

0 Kudos
Message 1 of 10
(2,374 Views)

You should look at using an Event Structure to handle when your controls change values.  You could even have a button for clearing the values.


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 10
(2,367 Views)

@Net2022 wrote:

I want to be able to calculate the side of any right triangle and be able to clear out the controls if all are filled. I have done this but with my code, I have to run the program again to clear it. I know I could set it so all fields are cleared by pressing a button, but is there a way to do it without pressing one?


  • The reason that you need to run our program over and over is because you don't have a toplevel while loop. Have a look at a simple state machine.
  • You need to decide when to clear the fields, because the user might want to see the result before they clear. Right?
  • All you string controls should be set to "limit to single line"
  • You need to convert to fractional numbers, not to integers.
  • The only place you need local variables is to write to these controls. You can read all values from the terminal directly, so none of the local set to read are ever needed here.
  • There is a primitive for "empty string?", you could even wire your string directly to the most case structure and make one case an empty string, the other the default.
  • You should only force a calculation if exactly one string is empty (i.e. two a non-empty)
  • There is a lot of duplicate code. You need much less.
  • Please do not maximize the front panel and diagram to the screen!
  • You have some glaring math errors (some missing squares or square-roots, etc.)
  • ...

see ow far you get.

0 Kudos
Message 3 of 10
(2,338 Views)

Thank you for your help, I'm only in the beginning stages of learning.

  • I tried using a while loop but it kept blinking from blank to an answer. When I put in a time to wait, it's either too slow or too fast. I know if I can fix my code for when to clear it, this problem will go away.
  • I tried using a clear button to clear the fields. However, when it clears the answer is now 0 for all the fields.
  • Thanks for catching my math mistake.
  • I used the local variables to make my code look neater, and I know it would look better if the code wasn't duplicated. I haven't figured out how to get the same results without it being duplicated though.

 

PT.pngPT 1.png

0 Kudos
Message 4 of 10
(2,324 Views)

I tried using event structure, but I think my code is still is a problem.

0 Kudos
Message 5 of 10
(2,314 Views)
Solution
Accepted by topic author Net2022

@Net2022 wrote:

Thank you for your help, I'm only in the beginning stages of learning.


You really need to start with the tutorials. None of your code is reasonable and again, virtually none of your local variables are needed. You need to understand the magic of the dataflow paradigm.

 

 

See if the attached makes any sense. Look up the functions used and try to understand the logic.

 

(A good program should have input validation and error handling (e.g. Hypot... need to be larger than side1 or side 2, resp. Inputs need to be valid numbers, etc.).

 

altenbach_0-1648359059259.png

 

0 Kudos
Message 6 of 10
(2,310 Views)

Thanks for your help. What you did makes sense. Looking at how you did it, I used some components that were similar to yours but wasn't able to get the correct results so I tried the way I posted. If I understand correctly (%.3f) gives how many significant digits after the integer? Why does it not work if it's there? Is it because 2 different inputs are going into the string?

 

I see where I was going wrong was in trying to use T/F for everything. It's complicated yet so simple. Thank you for your guidance. I'm going to see if I can tweak mine to make it more logical like yours.

0 Kudos
Message 7 of 10
(2,303 Views)

@Net2022 wrote:

 If I understand correctly (%.3f) gives how many significant digits after the integer? Why does it not work if it's there? Is it because 2 different inputs are going into the string?


You sentence makes absolutely no sense.

What is "it" that's there and what do you mean by "not work"? What inputs go into what string? Where?

Please clarify.

0 Kudos
Message 8 of 10
(2,298 Views)

I thank you for your help, but your reply sounds a little rude. I'm not trying to be a bother. I'm just trying to learn. To clarify I was asking about the (%.3f) that is in the string array containing the words side 1 is.. In order to understand the code, I recreated it and when the (%.3f) was left off the end the VI didn't run. I was trying to understand why the (%.3f) is needed.

0 Kudos
Message 9 of 10
(2,294 Views)

I wasn't rude, just did not understand what you are saying.

 

I cannot see what you wired where and words are insufficient to tell what you are doing wrong. There are millions of possibilities why something does not work. (wrong result, broken run button, computer crashes, etc.)

 

Is it possible that you wired the format to the wrong input of the format string operation? Compare with my example.

0 Kudos
Message 10 of 10
(2,288 Views)