UpperCase TextField and Mask on Jeremie Leroy CustomUI Desktop

Hi everybody!

This day Finally I’m playing with Jeremie Leroy’s Custom UI Desktop for Xojo
Who doesn’t heard about it, Its a kinda like of Framework for Xojo for build pretty cool UI’s (User Interfaces).

That is very useful, Cuz you only apply the style of all elements using a XML with the Style of elements.

but well, My issue here is that.

When I’m dealing with UI_TextField I notice that when I use the EVENT Textchange@Textfield, I Always used that code in order to change to uppercase when I’m writing:

Sub TextChange() dim i as integer = me.SelStart me.text = Uppercase( me.text ) me.SelStart = i End Sub

But I got an Stack Overflow Exception, I also tried to overpass it using an #pragma StackOverflow False but without success.

2.- Also I noticed that This “Textfield” Lacks of “MASK” so then I’ can’t use Mask on it

Any suggestions?

Also I tried doing #Pragma BreakonExceptions Off

and then analyzing the error with a Try catch
And when I done this It lets me write the first character in uppercase, but when I tried to type more characters Its shows the Colorwheel or waiting Cursor infinitely

I guess the reason for the overflow is that you are changing the text from within the TextChange event, which creates another text change, which gives you an endless event loop.
I would simply escape your code conditionally: If the text is already uppercase, do nothing.

[quote=381210:@Ulrich Bogun]I guess the reason for the overflow is that you are changing the text from within the TextChange event, which creates another text change, which gives you an endless event loop.
I would simply escape your code conditionally: If the text is already uppercase, do nothing.[/quote]
I’m doing this on Textchange event of the UI_TextField, and when I ran the same come on a “Normal” TextField that doesn’t happen

Here is how to do it in a cleaner fashion :

  • Add a timer to the window
  • Make it’s period 500
  • Set it to Off
  • Put this in the Action event handler :

If StrComp(TextField1.Text, Uppercase(TextField1.Text), REALbasic.StrCompLexical) >= 0 Then Dim i As Integer = TextField1.SelStart TextField1.Text = Uppercase( TextField1.Text ) TextField1.SelStart = i End If

Here is what you put in the TextField TextChange event :

Timer1.Mode = Timer.ModeOff Timer1.Mode = Timer.ModeSingle

The way it works is when the user types, it resets the timer, and keeps resetting it as long as there is typing. When the user stops, the timer fires, and after checking all is not in uppercase, the code you have used before puts everything in uppercase, half a second later.

The big advantage of such a technique, besides avoiding the stack overflow, is that the code does not execute if everything is already in uppercase.

[quote=381333:@Michel Bujardet]Here is how to do it in a cleaner fashion :

  • Add a timer to the window
  • Make it’s period 500
  • Set it to Off
  • Put this in the Action event handler :

If StrComp(TextField1.Text, Uppercase(TextField1.Text), REALbasic.StrCompLexical) >= 0 Then Dim i As Integer = TextField1.SelStart TextField1.Text = Uppercase( TextField1.Text ) TextField1.SelStart = i End If

Here is what you put in the TextField TextChange event :

Timer1.Mode = Timer.ModeOff Timer1.Mode = Timer.ModeSingle

The way it works is when the user types, it resets the timer, and keeps resetting it as long as there is typing. When the user stops, the timer fires, and after checking all is not in uppercase, the code you have used before puts everything in uppercase, half a second later.

The big advantage of such a technique, besides avoiding the stack overflow, is that the code does not execute if everything is already in uppercase.[/quote]
Wow men, That works amazingly!!! I set the timer to 200ms instead of 500ms has any consequence of do that?

Why not just set each character to upper case in the KEYDOWN event instead?

:frowning:

1.- Testing the suggestion of @Michel Bujardet it works well, Nevertheless, A funny fact occurs when you have more that one TextFields.
So, when I’m writing on the second Textfield where I’m noticing the uppercase timer.
And for example I made a mistake typing on the First Textfield(Where I have the timer). It doesnt allow me to select it and get back the Focus to the Second Textfield.

2.- When I use the suggestion of @Dave S , nothing happens, Thats what I’m doing.
May be I’m wrong:

KEY = Uppercase(key)

AT KEYDOWN Event

dang I thought that worked :frowning:
but this does

key=key.Uppercase
If AscB(key)<32 Then Return False
Me.seltext= key
Return True

[quote=381369:@Dave S]dang I thought that worked :frowning:
but this does

key=key.Uppercase If AscB(key)<32 Then Return False Me.seltext= key Return True [/quote]
Jipes! Neither that work, but It behave funny :smiley:
When you type only One character is written in uppercase

By the way I solve the problem, Stopping the UpperCase Timer suggested by @Michel Bujardet on the TEXTCHANGE event of the next TextField. :smiley: :smiley: :smiley:

dunno what to say… it worked perfectly here… but if you are on windows, they behave different

Nop, I’m on Mac, but I gonna test it on Windows.
Thanks Dave!

And about mask did you know if is it possible to do it on that UI_TextField?

[quote=381369:@Dave S]key=key.Uppercase
If AscB(key)<32 Then Return False
Me.seltext= key
Return True[/quote]
Hi Dave, I add this to the code that you gave me and it Works, without the Timer!!

key=key.Uppercase
If AscB(key)<32 Then Return False
Me.seltext= key
me.SelStart = me.Text.len
Return True

key=key.Uppercase
If AscB(key)<32 Then Return False
Me.seltext= key
me.SelStart = me.Text.len
Return True

'//return (Instr(AllowOnlyNumbersAndLetters,key)>0) 

Where: AllowOnlyNumbersAndLetters is a String Property = “<>,.-+;:_’*!#%&/()=?\[]{}$£@^|~¡¿^”

Note that I commented the last line I use that Line to restrict what characters are allowed.
But I can’t get it work together (the Uppercase method and the Allow Characters method)

Gerardo, do you have other event handler? Maybe there is a conflict with me.selstart because I made a simple example, just a text field and Dave’s code in keydown event and it works.

The only problem that I have is when I enter ‘~n’ trying to get the final result is ‘~’, I guess this is because I have to type 2 keys to get the special character (the same with , …). I’ll try to find a way to make it work.

Hi @Alberto De Poo , Yes I have another Event Handler, the TEXTCHANGE, where I analyze If the First 3 three letters are letters so do X
or If there first 4 letters are letters, then do Y