C critalsoft Member Licensed User Longtime User Jun 21, 2011 #1 Hi Erel, How can I set the maxlength of any textbox (edittext). Thanks
G gobblegob Member Licensed User Longtime User Jun 21, 2011 #2 Hi mate I had a quick look through the documentation and it doesn't mention length as a property, maybe you could try something like string length using the edittext textchanged event edittext1.text = string if string.length = "3" then edittext1.enabled = false else next if or something like that maybe, hope it helps. cheers Waz Last edited: Jun 21, 2011 Upvote 0
Hi mate I had a quick look through the documentation and it doesn't mention length as a property, maybe you could try something like string length using the edittext textchanged event edittext1.text = string if string.length = "3" then edittext1.enabled = false else next if or something like that maybe, hope it helps. cheers Waz
Erel B4X founder Staff member Licensed User Longtime User Jun 21, 2011 #3 You will need to handle the TextChanged event. If the text is longer than x characters you should call Substring to truncate it. Upvote 0
You will need to handle the TextChanged event. If the text is longer than x characters you should call Substring to truncate it.
davepamn Active Member Licensed User Longtime User Nov 3, 2014 #4 Erel said: You will need to handle the TextChanged event. If the text is longer than x characters you should call Substring to truncate it. Click to expand... Code: Copy Sub txtTruckNumber_TextChanged (Old As String, New As String) If New.Length>19 Then txtTruckNumber.text= New.SubString2(0,19) txtTruckNumber.SelectionStart=19 EndIf End Sub The selectionStart keeps the cursor at the end of the textbox Upvote 0
Erel said: You will need to handle the TextChanged event. If the text is longer than x characters you should call Substring to truncate it. Click to expand... Code: Copy Sub txtTruckNumber_TextChanged (Old As String, New As String) If New.Length>19 Then txtTruckNumber.text= New.SubString2(0,19) txtTruckNumber.SelectionStart=19 EndIf End Sub The selectionStart keeps the cursor at the end of the textbox
sirjo66 Well-Known Member Licensed User Longtime User Jul 11, 2018 #6 I re-open this thread because I want to contribute with my solution, for me better than post #4, because it works better with SelectionStart when you change text at the middle of EditText Code: Copy Sub txtTruckNumber_TextChanged (Old As String, New As String) If New.Length > 19 Then Dim pos As Int = Codice.SelectionStart Codice.Text = Old Codice.SelectionStart= pos - 1 End If End Sub Last edited: Jul 11, 2018 Upvote 0
I re-open this thread because I want to contribute with my solution, for me better than post #4, because it works better with SelectionStart when you change text at the middle of EditText Code: Copy Sub txtTruckNumber_TextChanged (Old As String, New As String) If New.Length > 19 Then Dim pos As Int = Codice.SelectionStart Codice.Text = Old Codice.SelectionStart= pos - 1 End If End Sub