LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to accept only 4 or less hex characters in string control

Solved!
Go to solution

Hi,

I want to accept only up to 4 hex characters in a string control. I dont want to use "hex display" property.

How is it possible? I have String control key down? event in event case, I tried it with regular expressions [0-9a-fA-F]{4} but then I have to accept left, right, delete, backspace, home keys as well.

0 Kudos
Message 1 of 6
(3,040 Views)
Why do you want to make it so difficult for yourself and not simply use a numeric U8 set for hex display. If you need a string to be passed to something, you have a simple conversion. What advantage to the user for a string?
Message 2 of 6
(3,026 Views)
Solution
Accepted by kahlenberg

I agree with Dennis that you seem to be making life difficult for yourself.  However, you did ask the equivalent (as I understand it) "How can I allow the user to type "1", "2", "Ctrl-A", "B", "Ctrl-C", "D" and get this recognized as the string "12BD".  If you really want to do this, here is one way (I was lazy and left the answer as an array of 4 1-character strings).  I use PlatMods to exclude having any "modification" key other than Shift down, convert the numeric Char into a string, then count acceptable Hex letters and conditionally add them to the output array, stopping when I have 4 characters. 

Four Hex Chars.png

Bob Schor

0 Kudos
Message 3 of 6
(3,014 Views)

Thanks a lot for answers and code.

Actually, I dont want it, user wants to do so. He is not familiar with string input with "hex display".

0 Kudos
Message 4 of 6
(2,998 Views)
That does not make any sense. A user would not know that a numeric control or string control is even being used. You type a valid hex value with the keyboard either way. By using a string control, it just creates more work and adds confusion. Part of your job is to point out such senseless requests.
0 Kudos
Message 5 of 6
(2,988 Views)

Point well taken.  I'm not used to criticizing why someone wants to do something that I think is silly -- I (naively) assume that they have a good reason for doing it that way ...

 

BS

0 Kudos
Message 6 of 6
(2,964 Views)