ProperCase(TextEdit.text)?

lawboy

Member
Licensed User
Longtime User
Is there an example of the workaround to have a text box do proper case? I am getting the correct result with the code below in a message box, but how do I get the text box to accept the value along with the rest of what is being typed.

B4X:
Sub Globals
Dim EditText1 As EditText

Dim edit_text As String
Dim first_char As Int
Dim upper_char As String
Dim txtLen As Int
Dim Final As String

End Sub

Sub EditText1_TextChanged (Old As String, New As String)
edit_text = EditText1.Text
first_char= edit_text.CharAt(0)
upper_char = first_char.ToUpperCase
txtLen = edit_text.Length
For i = 0 To txtLen -1
If i = 0 Then
Final = upper_char
Else
Final = Final & upper_char.CharAt(i)
End If
Next

Msgbox(Final,"")

End Sub
Thanks
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Process_Globals
    
End Sub

Sub Globals
    Dim EditText1 As EditText
    Dim ignoreNextTextChangedEvent As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    EditText1.Initialize("EditText1")
    activity.AddView(EditText1, 10dip, 10dip, 200dip, 50dip)
End Sub

Sub EditText1_TextChanged (Old As String, New As String)
    If ignoreNextTextChangedEvent = True Then
        ignoreNextTextChangedEvent = False
        Return
    End If
    If new.Length > 0 Then
        Dim s As String
        s = New.SubString2(0, 1).ToUpperCase & New.SubString(1).ToLowerCase
        ignoreNextTextChangedEvent = True
        EditText1.Text = s
        EditText1.SelectionStart = EditText1.Text.Length
    End If
End Sub
 
Upvote 0
Top