LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting an alphanumeric constant based on number

Solved!
Go to solution

Hi. I need to create a control that lets the user advance an alphanumeric label. It needs to run from 1-9 and then A-Z. So entry one is 1, entry two is 2, but entry 10 is a, and entry 11 is b, etc.

 

I know I can just use a combo box, but what if I wanted to use a numeric constant to make users understand that going "up" one advances according to this pattern (and they're not picking in any order from a list)? What I want is kindof the opposite of an enum, where a number corresponds to a value on a list that goes 123456789ABCDEFGH....

 

What's the cleanest way to do this?

0 Kudos
Message 1 of 7
(2,830 Views)

So it sounds like you want an enumerated list, but don't want them to be able to "open" it to select from the dropdown, is that right?

 

If so, I don't think there's a way to prevent the user from being able to click it to select the value in a list. Discarding all MouseDown events won't work either as that discards MouseDowns on the increment/decrement buttons. You *could* do some math to figure out if the MouseDown is on the button or on the increment/decrement buttons, but I generally stay away from that sort of thing as Windows magnification settings or font settings can be obnoxious to deal with.

 

You can disable the control (right click->advanced->enabled state->disabled, then hide the increment/decrement buttons (right click->visible items) and add some of your own buttons, handled in an event structure like so:

 

enum.png

 

If you don't like the look of those buttons, you could use a regular numeric control for its increment/decrement buttons and hide the display behind the enum. You'd need to handle it slightly differently, but nothing too bad.

Message 2 of 7
(2,807 Views)

Thanks, BertMcMahan! That idea seems valid. It might be a little more complicated than I need, because I'm okay with the user seeing actual numbers (when they get to #11, they can see 11, not 'b') as long as there's something on the block diagram converting numbers greater than 9 into letters. Ideally I'd like them to see the list progressing linearly from 1-9 to A-Z, but what's really important is that they recognize that they're progressing through a numbering system that is labelled differently based on where they are in the list.

 

Maybe I can use a numeric control and a separate indicator for what I want them to see as a "label", by having the control be read as a numeric and converted (if necessary) into a letter? How do I do this intelligently without a case structure for every single value greater than 9?

 

Edit: The max length of the list is 35, because once they get to Z it should stop.

0 Kudos
Message 3 of 7
(2,786 Views)

Ah, that's very easy then. Just connect your numeric control to an enum indicator- it'll auto-coerce just fine. Make sure your numeric control is an integer type though (I'd use a U8, but it won't matter). The indicator won't be clickable. If you want it to update in real time, put that in an event structure so it updates the enum when you increment the numeric.

 

Right click the Numeric to set its properties to give an allowable range of 1-35, and it'll stop when it gets to 35. If you want it to wrap around, you'll need to do manual checking in an event structure, otherwise it'll just stop at 35 and won't increment anymore.

 

Oh, and you'll need to add a -1 to the value in the selector, as the Enum will use the number of the item in its list. For example, if the first element in the enum is "1", then wiring a 0 to the Enum will make it display 1, as it's zero-indexed. Wiring a value of 1 to the enum will select the second item in the enum (again, as it's zero-indexed, it'll count 0, 1, 2, 3, etc.)

Message 4 of 7
(2,779 Views)

That makes sense - the user will be clicking through a numeric list that goes 1-35, and next to that they'll see an alphanumeric list advancing that goes 1-9 A-Z.

 

However, if elsewhere on my spreadsheet I need to use the values from the second list (the 1-9A-Z one), is that going to work? The control and indicator will only be returning numeric values of 1-35. Is there a way to harvest the actual enum values, rather than their numbers?

0 Kudos
Message 5 of 7
(2,772 Views)
Solution
Accepted by topic author sbernie2

Yep, oddly enough, using Format Into String. You'll need to actually coerce the wire type to the type of the enum though instead of letting it auto-coerce (using Coerce to Type with an enum constant, preferably a typedef):

 

enum2.png

Message 6 of 7
(2,768 Views)

That's crazy smart, thanks! Had no idea you could coerce to a type like that.

0 Kudos
Message 7 of 7
(2,757 Views)