A Letter in a TextField

Hello everyone
Xojo

I am grateful for the interest and scope of the following:

How can I make a text only allow me to enter a single letter?
for example, A, B, C, D, E or F

Do not allow numbers or other characters

Any ideas will be greatly appreciated.

Cordially,
Raúl Juárez Pulache

http://documentation.xojo.com/index.php/TextEdit.Mask

First, wouldn’t you be better served by a popup menu in that case? Or even a series of radio buttons?

But if you really want to do this, keep a property that records the current contents of the field. In the TextChange event, see if the new value is valid. If so, update the property. If not, restore the contents of the property. Remember to allow the users to clear the field too, and make adjustments for selection. For example, if the contents of the field is “A” and then changes to “AB”, the user probably entered “B” next to “A”. In that case, you’d change it to just “B”.

You can manage this in the KeyDown event too, but that won’t account for the user pasting or dropping text into the field.

Or just use a popup menu or series of radio buttons. :slight_smile:

I think it can be a solution, of the many

If Me.text.Len> 0 then
Me.text = Uppercase (Me.text)
Dim pos As Integer = Instr (“ABCDEFGHIJKLMNOPQRSTUVWXYZ”, Me.text)
If pos = 0 then
MsgBox “Enter a Letter”
Me.text = “”
Me.SetFocus
End If
End If

A thousand apologies I was not very explicit

All ideas are appreciated

Thank you very much

Raul Juarez Pulache

Purely out of curiosity, in what way does the TextField’s mask not accomplish what you are trying to achieve? For example, setting the mask to ‘A’ only allows the user to enter a single alphabetic character. You could then, of course, Uppercase() it if that’s a requirement.

UI-wise, I’d agree with Kem with his popup menu suggestion. But I’m still curious why the mask didn’t work for you :slight_smile: