Edit Text object cause my app to crash! Help needed

ashrafidkaidek

Member
Licensed User
Longtime User
My app has an Edit Text object and I’m trying to limit:
1) Number of characters allowed in the Edit Text object.
2) Specific characters only will be allowed to be entered.

Below you will find the code I’m using, which has no error, but when I try to run the app and start adding characters to the Edit Text object the app crashes without showing any error.
Any advice?
Thank you all

B4X:
Sub EditFoldrName_TextChanged (Old As String, New As String)
   Dim pline As String = EditFoldrName.Text
   
   If pline.Length > 15 Then
       EditFoldrName.Text = pline.SubString2(0,15)
       EditFoldrName.SelectionStart = 15
   Else
      If pline.Length = 0 Then Return
      Dim FinalTxt, Chrk, OkCh As String
      
      For i = 0 To (pline.Length-1)
         Chrk = pline.SubString2(i, i+1)
         OkCh = "no"
                If Chrk = "0" Then OkCh = "yes"
                If Chrk = "1" Then OkCh = "yes"
                If Chrk = "2" Then OkCh = "yes"
                If Chrk = "a" Then OkCh = "yes"
                If Chrk = "b" Then OkCh = "yes"
                If Chrk = "c" Then OkCh = "yes"
                If Chrk = "@" Then OkCh = "yes"
                If Chrk = "#" Then OkCh = "yes"
                If Chrk = "$" Then OkCh = "yes"
            
         If OkCh = "yes" Then
            FinalTxt = FinalTxt & Chrk   
         End If
      Next
      '---------------------------------------
      EditFoldrName.Text = FinalTxt
      EditFoldrName.SelectionStart = EditFoldrName.Text.Length
   End If
   
End Sub
 

giga

Well-Known Member
Licensed User
Longtime User
My app has an Edit Text object and I’m trying to limit:
1) Number of characters allowed in the Edit Text object.
2) Specific characters only will be allowed to be entered.

Below you will find the code I’m using, which has no error, but when I try to run the app and start adding characters to the Edit Text object the app crashes without showing any error.
Any advice?
Thank you all

B4X:
Sub EditFoldrName_TextChanged (Old As String, New As String)
   Dim pline As String = EditFoldrName.Text
   
   If pline.Length > 15 Then
       EditFoldrName.Text = pline.SubString2(0,15)
       EditFoldrName.SelectionStart = 15
   Else
      If pline.Length = 0 Then Return
      Dim FinalTxt, Chrk, OkCh As String
      
      For i = 0 To (pline.Length-1)
         Chrk = pline.SubString2(i, i+1)
         OkCh = "no"
                If Chrk = "0" Then OkCh = "yes"
                If Chrk = "1" Then OkCh = "yes"
                If Chrk = "2" Then OkCh = "yes"
                If Chrk = "a" Then OkCh = "yes"
                If Chrk = "b" Then OkCh = "yes"
                If Chrk = "c" Then OkCh = "yes"
                If Chrk = "@" Then OkCh = "yes"
                If Chrk = "#" Then OkCh = "yes"
                If Chrk = "$" Then OkCh = "yes"
            
         If OkCh = "yes" Then
            FinalTxt = FinalTxt & Chrk   
         End If
      Next
      '---------------------------------------
      EditFoldrName.Text = FinalTxt
      EditFoldrName.SelectionStart = EditFoldrName.Text.Length
   End If
   
End Sub

Is it doing it in Debug mode as well??
 
Upvote 0

ashrafidkaidek

Member
Licensed User
Longtime User
I'm using a physical device to test my app (after creating a bridge between Basic4Android and the device), when running the app from Basic4Android i keep the debug option selected . . . I'm not sure if running the app this way is equivalent to a debug mode or not . . .
 
Upvote 0

ashrafidkaidek

Member
Licensed User
Longtime User
Erel,

The code as i have it does not go into endless loops, and i have noticed that when i remove the for loop (in other words just check one corrector) the code runs fine. to me there is something does not make since, because the code does not edit or change the text in the "Edit Text" object while looping.

It seems to me that there are max. number of operation allowed in the "TextChanged" event. if so this should be fixed.

I have been doing this kind of coding using Visual Studio and never had any problem with it.

Does anybody know of a solution around this problem? This is a must have task in my app.

Regards
 
Upvote 0
Top