Uppercase !

superbabicka

Member
Licensed User
I know that this is stupid question but I'm agonize with... :sign0161:

(I want to make desktop application)
I have TextBox (Only One) And after key_press I want string automatically go to uppercase.
I have this:

Sub TextBox1_KeyPress(key)
TextBox1.Text = StrToUpper(TextBox1.Text)
End Sub

So, when I push First Key, nothings happen - (lowercase), and when I push second key, then the First Key Is Uppercase, the CURSOR is on the beginning of the TextBox1 focus, and ONE FROM ANOTHER every next key is Uppercase, BUT MY WORDS IS TOPSY-TURVY ...

Aaaaaaahhhhh

Some Help...?

Thx
 

agraham

Expert
Licensed User
Longtime User
You have two problems here. Firstly you get the KeyPress event before that key is added to the textbox so it doesn't get uppercased. Secondly the insertion point is lost when you uppercase the string.

The solution to the first is to use the new Door library http://www.b4x.com/forum/showthread.php?t=2038 to catch the TextChanged event which occurs after the key is added. The solution to the second is to save and restore the insertion point.
 

Attachments

  • UpperCase.zip
    4.5 KB · Views: 242
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should use the TextChanged event (with the Door library):
B4X:
'obj is an Object, TextBox1ChangedEvent is an Event.
Sub App_Start
    Form1.Show
    obj.New1(false)
    obj.FromControl("textbox1")
    TextBox1ChangedEvent.New1( obj.Value,"TextChanged")
End Sub

Sub TextBox1ChangedEvent_NewEvent
    textbox1.text = StrToUpper(TextBox1.Text)
    textbox1.SelectionStart = StrLength(textbox1.text)
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…