Capitalizing Text

bishmedia

Member
Licensed User
Longtime User
I have found a piece of code that capitalized only the first letter of the input, how easy is it to make all charactors in Uppercase when the user inputs into the field??

B4X:
Sub txtPostcode_TextChanged (Old As String, New As String)
   txtPostcode.InputType = Bit.OR(txtPostcode.INPUT_TYPE_TEXT, 4096)
End Sub
 

stevel05

Expert
Licensed User
Longtime User
Or you could set the input type on the field. Check TYPE_TEXT_FLAG_CAP_CHARACTERS InputType here, which will use a standard input type.

B4X:
Dim InpTyp As SLInpTypeConst

InpTyp.SetInputType(txtPostcode,Array As Int(InpTyp.TYPE_CLASS_TEXT,InpTyp.TYPE_TEXT_FLAG_CAP_CHARACTERS))
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You can set it in activity create, it only has to be done once.

From the example project:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim InpTyp As SLInpTypeConst
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim EditText1 As EditText
   Dim EditText2 As EditText
   Dim EditText3 As EditText
   Dim Edittext4 As EditText
   Dim Edittext5 As EditText
   Dim EditText6 As EditText
   Dim EditText7 As EditText
   Dim EditText8 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")

   Activity.LoadLayout("1.bal")

   InpTyp.SetInputType(EditText1,Array As Int(InpTyp.TYPE_CLASS_NUMBER,InpTyp.TYPE_NUMBER_FLAG_SIGNED,InpTyp.TYPE_NUMBER_FLAG_DECIMAL))

   InpTyp.SetInputType(EditText2,Array As Int(InpTyp.TYPE_CLASS_DATETIME,InpTyp.TYPE_DATETIME_VARIATION_TIME))

   InpTyp.SetInputType(EditText3,Array As Int(InpTyp.TYPE_CLASS_TEXT,InpTyp.TYPE_TEXT_VARIATION_EMAIL_ADDRESS))
   
   InpTyp.SetInputType(Edittext4,Array As Int(InpTyp.TYPE_CLASS_TEXT,InpTyp.TYPE_TEXT_VARIATION_NORMAL))
   
   InpTyp.SetInputType(Edittext5,Array As Int(InpTyp.TYPE_CLASS_TEXT,InpTyp.TYPE_TEXT_VARIATION_PASSWORD))
   
   InpTyp.SetInputType(EditText6,Array As Int(InpTyp.TYPE_CLASS_TEXT,InpTyp.TYPE_TEXT_FLAG_NO_SUGGESTIONS))
   
   InpTyp.SetInputType(EditText7,Array As Int(InpTyp.TYPE_CLASS_DATETIME,InpTyp.TYPE_DATETIME_VARIATION_DATE))
   
   InpTyp.SetInputType(EditText8,Array As Int(InpTyp.TYPE_CLASS_TEXT,InpTyp.TYPE_TEXT_FLAG_AUTO_CORRECT))
   
End Sub
 
Upvote 0

iligeo

New Member
Licensed User
Longtime User
Capitalizing Edit

Sub edit_TextChanged (Old As String, New As String)
If edit.Text<>edit.Text.ToUpperCase Then
edit.Text = edit.Text.ToUpperCase
edit.SelectionStart = edit.Text.Length
End If
End Sub

This works for me ..:)
 
Upvote 0
Top