Problem with FocusChanged

dbryan

Member
Licensed User
Longtime User
The first issue I ran into when generating members is that the procedure did not seem to generate correctly. I already did a bug alert on that.

So I wrote the following procedure and it doesn't get called. Can someone tell me how I'm doing this wrong? I want this to execute every time the field loses focus, but when debugging it never seems to trigger.

B4X:
Dim addTxtSSN As EditText

Sub addTxtSSN_FocusChanged (HasFocus As Boolean)
   Dim s As String
   Dim myError As Int
   If HasFocus = False Then
      If addTxtSSN.Text <> "" AND addTxtSSN <> Null Then
         myError = 0
         s = addTxtSSN.Text
         If s.Length <> 11 Then 
            myError = 1
         Else
            If IsNumber(s.SubString2(0,0)) = False Then myError = 1
            If IsNumber(s.SubString2(1,1)) = False Then myError = 1
            If IsNumber(s.SubString2(2,2)) = False Then myError = 1
            If s.SubString2(3,3) <> "-" Then myError = 1
            If IsNumber(s.SubString2(4,4)) = False Then myError = 1
            If IsNumber(s.SubString2(5,5)) = False Then myError = 1
            If s.SubString2(6,6) <> "-" Then myError = 1
            If IsNumber(s.SubString2(7,7)) = False Then myError = 1
            If IsNumber(s.SubString2(8,8)) = False Then myError = 1
            If IsNumber(s.SubString2(9,9)) = False Then myError = 1
            If IsNumber(s.SubString2(10,10)) = False Then myError = 1
         End If
         If myError = 1 Then
            Msgbox("Invalid SSN format","Invald Format")
            addTxtSSN.Text = ""
         End If
      End If
   End If
End Sub
 

Mahares

Expert
Licensed User
Longtime User
Try this corrected code. It worked for me:

B4X:
Dim addTxtSSN As EditText    'dimed in Globals
B4X:
Sub addTxtSSN_FocusChanged (HasFocus As Boolean)
    Dim s As String
    Dim myError As Int
    If HasFocus = False Then
        If addTxtSSN.Text <> "" AND addTxtSSN <> Null Then
            myError = 0
            s = addTxtSSN.Text
            If s.Length <> 11 Then 
                myError = 1
            Else
                If IsNumber(s.SubString2(0,1)) = False Then myError = 1
                If IsNumber(s.SubString2(1,2)) = False Then myError = 1
                If IsNumber(s.SubString2(2,3)) = False Then myError = 1
                If s.SubString2(3,4) <> "-" Then myError = 1
                If IsNumber(s.SubString2(4,5)) = False Then myError = 1
                If IsNumber(s.SubString2(5,6)) = False Then myError = 1
                If s.SubString2(6,7) <> "-" Then myError = 1
                If IsNumber(s.SubString2(7,8)) = False Then myError = 1
                If IsNumber(s.SubString2(8,9)) = False Then myError = 1
                If IsNumber(s.SubString2(9,10)) = False Then myError = 1
                If IsNumber(s.SubString(10)) = False Then myError = 1
            End If
            If myError = 1 Then
                Msgbox("Invalid SSN format","Invalid Format")
                addTxtSSN.Text = ""
             Else
                 Msgbox("You got it right!","")
            End If
        End If
    End If
End Sub
 
Upvote 0

dbryan

Member
Licensed User
Longtime User
The problem isn't in the code. the problem I'm having is that the Sub is not being called as the focus is lost/gotten. I have it in debug mode and marked to stop when it is executed, but it never activates.

I already had it defined in globals. I wish I could understand why it isn't activating.
 
Upvote 0
Top