LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to set a string input to accept only 1 and 0 (binary data)

Hi
I want to write a program that is supposed to take only binary data from the user. So I put a string control onto the front panel, wanting the user to be able to only type 1 or 0 in it. Is there a way to do that?
Thanks
0 Kudos
Message 1 of 10
(4,414 Views)
The easiest thing to do is to use a numeric control. Set the Representation to integer, Format & Precision to binary, and Data Range 0 to 1.
Message 2 of 10
(4,407 Views)

Hi

I want to user to be able to enter a stream of binary data of length up to 4000 digits....so is there a way to do that? I dont want to use numeric because the stream is long.

Thank you

0 Kudos
Message 3 of 10
(4,405 Views)
When you said either 0 or 1, I assumed you only wanted one bit. You could use a numeric array which could be any length. Frankly, I don't see how you can expect a user to enter up to 4000 digits but if you want to use a string, try setting it to Update Value While Typing and then you can use a Value Change event for the string control. If the last character is not a 0 or 1, then you could delete the last character.
Message 4 of 10
(4,401 Views)
Here is a vi that will only accept 0 and 1 from the keyboard as inputs to the string.
- tbob

Inventor of the WORM Global
Message 5 of 10
(4,396 Views)

One easy way is to use filtering events. In this particular case, you would discard the input except for the allowed keys. In order to be able to edit the entered string, you also want to allow e.g. backspace and delete in addition ot 0 and 1.

The attached simple example (LabVIEW 7.1) shows how to filter all inputs to the string control, except for the four keys mentioned above. Let me know if you have questions. Modify as needed.

Message Edited by altenbach on 10-27-2005 04:34 PM

Message 6 of 10
(4,393 Views)
My example above had a slight flaw because it did not filter "key repeat?", just "key down?". For example if you would hold down the "2" key, it will start entering once the key-repeat timeout is reached.
 
To fix this, we simply need also monitor for the "key repeat?" filtering event in the same event case. See attached modification (LAbVIEW 7.1).
Message 7 of 10
(4,381 Views)
That works really well. Thank you so much.Smiley Happy
0 Kudos
Message 8 of 10
(4,352 Views)
Another slight flaw is that the string accepts Enter for a new line. It is easily fixed by setting it to "Limit to single line".

I strongly suggest a fancier UI for this type of input. The 4000 bits would be a nightmare to check. Putting 20 or 50 bits per line and a numbering column at the left might be appropriate.


LabVIEW, C'est LabVIEW

0 Kudos
Message 9 of 10
(4,335 Views)


@Jean-Pierre Drolet wrote:
Another slight flaw is that the string accepts Enter for a new line. It is easily fixed by setting it to "Limit to single line".

True, it allows any non-ASCII through. Another solution would be to use some logical combination of VKey and Char, but it could get complicated. One of the simpler ways is the use of scancode and shift, as in the attached modification. Now ENTER, etc. is also discarded.
 
I also agree that none of this seems appropriate to enter 4000 "0/1" characters on a fromt panel. 😮
0 Kudos
Message 10 of 10
(4,328 Views)