Not understanding Text Masks

I have a mask that is “AAA” that only allows 3 alphabetic characters. This mask works as expected.

Then I do “>A<AA” where the first alphabetic character is capitalized and the rest are lower case. Except the number of characters allow me to go on forever?

Also Using the masks in a DesktopListbox do not allow me to use a validation event like a normal textboxcontrol. Is there a way to expose that event?

This is not too helpful, but I would confirm the behavior. The presence of “<” or “>” destroys the “entry is mandatory” effect of any A that follows. “>###” does not destroy the mandatory effect of the digit specifier. You cannot type as many digits as you might want.

But once the mask contains a “<”. any “A” or “a” that follows has changed in meaning – it now means type however many characters as you want.

You might get the effect you need by coding in the TextChanged Event.

put something like this in there:

Me.Text = Me.Text.Left(3)

Var char() As String
char() = Me.Text.ToArray("")

If Me.Text.Length > 0 Then char(0) = char(0).Uppercase
If Me.Text.Length > 1 Then char(1) = char(1).Lowercase
If Me.Text.Length > 2 Then char(2) = char(2).Lowercase

Me.Text = String.FromArray(char, "")

1 Like

Thank you Robert for the nice solution. I was doing this to understand the black magic art of Masks. It seems to me that the Length would always win out over any other option. Almost seems to be a bug. “>####” works without the > but doesn’t with… and it didn’t capitalize my numbers??? grin

Dale

I don’t have a better solution than the TextChanged approach, but just chiming in that I have been trying to wrap my head around text masks for a literal decade and I just don’t get it.

I don’t know if it’s a buggy implementation or if it’s just my feeble brain that can’t grasp it, but this is one area where we need much, much more detailed documentation.

you have lowercase numbers ? :wink:

1 Like