LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Slide Color "Bad Programing"

Hi!

 

I'm working on a way to change the slide fill color dynamically, in the picture you can see what i came up to, however in most of the post i see in the forum, they say this is "bad programing" and I want to know if there is a better method to do this.

 

color_slider.png

 

This slide is going to show a tank's level thus in the VI is going to be a data adquisition, this is why i want to improve the code.

 

Thanks in advance.

 

Cesar.

 

PS: let me explain what i do: the tank level changes between 10 and 40 so i took that number and scaled so on the green port of the RGB to color vi i've a signal that changes between 0 and 255, this makes the color change on the property node

0 Kudos
Message 1 of 5
(3,524 Views)
Two problems.

1. You are setting the property over and over again even if the input hasn't changed.

2. There is no delay in the loop.

Solution to both problems is to use an event-driven approach.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 5
(3,494 Views)

While it's true that there's no need to repeatedly set the color, I wouldn't actually call it a problem, especially if your data is coming from DAQ and not from the user. LV can usually manage just fine with that if you're only doing it a few times a second, so I would say that your only real problem is that you don't have a wait, because that would cause the loop to run as fast as possible and eat up all the CPU time. Every long-running loop should have something delaying it.

 

A second problem is the dynamic data. I never worked with it, so I don't know it well enough, but the main reason I haven't worked with it is that I can't understand or predict how it will behave, because it's a kind of magic data type which automatically adapts and coerces to fit the code, so I would suggest you replace that piece of code with one of your own, which uses a primitive numeric data type.

 

Since you're doing a simple linear conversion, it's simply a matter of a straight line equation, which you probably learned in middle school. I believe LV has some VIs which ship which already do that, and you can probably also right click the express VI and open its FP, which will convert it to a regular VI you can look at. Or you can write the code on your own.


___________________
Try to take over the world!
0 Kudos
Message 3 of 5
(3,469 Views)

Hi cdarangoo,

 

I also would suggest to replace the express vi; in this particular case, I would use an expression node from the numeric palette:

 

2015-04-24_expression_node.png

 

 

Regards,
Alex

0 Kudos
Message 4 of 5
(3,444 Views)

Hi again thank you all for your answers:

 

mikeporter and tst:

 

In the hurry making the post i don't really post the complete code, just the changing color part, that's why i dont have the delay in the while loop.

 

I guess as a final solution, i'll change the express VI as alexderjuengere suggested and take the tst advice about the continous color seting.

 

Thanks Again here is a final picture of my project:

 

Sin título.png

 

Cesar

0 Kudos
Message 5 of 5
(3,407 Views)