LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Clearing Text a Control

Solved!
Go to solution

Hello, first of all let me say that I am new to Labview, but have been working with it for a little while now and am starting to get the hang of it.  The project I am working on is a VA for a test system for a bunch of cables, each one serialized.  The idea is that the user selects a directory, and then for each test enters a serial number while the VI grabs the data (from a network analyzer) and writes it to a text file in the selected directory with the name being the serial number with the .txt extension.

 

I have this working pretty well, but we would like to integrate a barcode scanner.  We have a bunch of scanners which emulate USB keyboards, so it is simple to have the user just click in the text control for serial number, and scan the cable.  However, we would also like to be able to have it so that the user does not need to do anything other than connect the cable and scan it.  The scanners have are set up to append a carriage return to the end of the number it has just scanned, basically simulating hitting the Enter key.  I set the button I use to trigger the test to toggle on Enter, so just scanning a bar code will start the test and save the data.  However, it will not clear the text control; rather, the previous serial number sits in there while the new one is appended to the end.  How can I clear this field programmatically?

0 Kudos
Message 1 of 8
(4,229 Views)
Solution
Accepted by linuxpyro
Write an empty string to the control's local variable.
0 Kudos
Message 2 of 8
(4,218 Views)
Probably several ways to do this but the first one that comes to mind is thus. If that string control default data is blank (saved as default data) you could, by right clicking the control on the block diagram, create an invoke node and select the reintialize to default method. Place this invoke node in the appropriate part of your program after you have read that controls data. This will again blank out the data for the next serial number.
Now Using LabVIEW 2019SP1 and TestStand 2019
Message 3 of 8
(4,216 Views)

You can just use a local variable of the control and write an empty string to its value, or use a Property Node and select the Value property. You can create either one by right-clicking on the control and selecting Create -> Local Variable or Create -> Property Node. With a property node you can use the error clusters to establish data dependency to make sure the clearing of the control only occurs after the test is finished. If you use the local variable you must make sure that that writing will not occur until you've actually completed the test. Here's a simple example of what is meant by this:

 

 

0 Kudos
Message 4 of 8
(4,214 Views)

smercurio_fc wrote:

You can just use a local variable of the control and write an empty string to its value, or use a Property Node and select the Value property. You can create either one by right-clicking on the control and selecting Create -> Local Variable or Create -> Property Node. With a property node you can use the error clusters to establish data dependency to make sure the clearing of the control only occurs after the test is finished. If you use the local variable you must make sure that that writing will not occur until you've actually completed the test. Here's a simple example of what is meant by this:

 

 


I would recommend using GovBob's approach of using the invoke node to reinitialize the control rather than using property nodes or local variables.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 8
(4,190 Views)

Mark Yedinak wrote:

smercurio_fc wrote:

You can just use a local variable of the control and write an empty string to its value, or use a Property Node and select the Value property. You can create either one by right-clicking on the control and selecting Create -> Local Variable or Create -> Property Node. With a property node you can use the error clusters to establish data dependency to make sure the clearing of the control only occurs after the test is finished. If you use the local variable you must make sure that that writing will not occur until you've actually completed the test. Here's a simple example of what is meant by this:

 

 


I would recommend using GovBob's approach of using the invoke node to reinitialize the control rather than using property nodes or local variables.


Why? Why go though the VI Server when a simple local variable is just as effective, and probably way faster. The only issue would be to eliminate a race condition, which is solved trivially. Local variables are not EVIL.

0 Kudos
Message 6 of 8
(4,185 Views)
Alright guys, I think I'm just going to go ahead and use the local variable.  Thanks for the input!
0 Kudos
Message 7 of 8
(4,172 Views)

smercurio_fc wrote:

Mark Yedinak wrote:

smercurio_fc wrote:

You can just use a local variable of the control and write an empty string to its value, or use a Property Node and select the Value property. You can create either one by right-clicking on the control and selecting Create -> Local Variable or Create -> Property Node. With a property node you can use the error clusters to establish data dependency to make sure the clearing of the control only occurs after the test is finished. If you use the local variable you must make sure that that writing will not occur until you've actually completed the test. Here's a simple example of what is meant by this:

 

 


I would recommend using GovBob's approach of using the invoke node to reinitialize the control rather than using property nodes or local variables.


Why? Why go though the VI Server when a simple local variable is just as effective, and probably way faster. The only issue would be to eliminate a race condition, which is solved trivially. Local variables are not EVIL.


One reason that comes to mind is if you end up reinitializing the control in multiple places. If you use a constant then you will need to update all the places you initialize the control to it's default value. Whereas using the Invoke node allows you to assign the default value as an attribute of the control itself and should that value change you have one place to update it.

 

As a general rule of thumb I try to avoid the use of local variables and property nodes and stick with pure data flow programming. Granted this is not always possible. By not using them I tend to think more about my design and architecture of my application and develop something that is more robust and flexible. Over time you build your bag of tricks and find you only need to use them on rare occasions.

 

And for the record I never said they were evil. I said the invoke node was my prefered method.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 8
(4,168 Views)