Android Question Condition as Boolean taken as Number

johnaaronrose

Active Member
Licensed User
Longtime User
I'm trying to test that a particular EditText's value (i.e. Text property) is in any of specified ranges. When I run the following code, I get a Java Number Format Exception: Invalid Double "SO" [on the bo = (GR >= "HL" AND GR <= "HZ") line] preceded by:
GR=SO
GR.Length=2
GR.Length OK

I thought that (GR >= "HL" AND GR <= "HZ") should result in False.

B4X:
Sub edtOSGBGridRef1Valid As Boolean
    Dim GR As String
    GR = edtOSGBGridRef1.Text.Trim
    Log("GR="&GR)
    Log("GR.Length="&GR.Length)
    If GR.Length <> 2 Then
        Log("OSGB Grid Reference Map must be 2 characters")
        ToastMessageShow("OSGB Grid Reference Map must be 2 characters", True)
        Return False
    End If
    Log("GR.Length OK")
    Dim bo As Boolean
    bo = (GR >= "HL" AND GR <= "HZ")
    Log("bo="&bo)
    Log("bo="&bo)
    If Not(GR >= "HL" AND GR <= "HZ") AND _
      Not(GR >= "JL" AND GR <= "JW") AND _
        Not(GR >= "NA" AND GR <= "NZ") AND _
        Not(GR >= "OA" AND GR <= "OW") AND _
        Not(GR >= "SA" AND GR <= "SZ") AND _
        Not(GR >= "TA" AND GR <= "TW") Then
        Log("Valid OSGB Grid Ref Map")
        ToastMessageShow("Valid OSGB Grid Ref Map", True)
    Else
        Log("OSGB Grid Reference Map not HL-HZ/JL-JW/NA-NZ/OA-OW/SA-SZ/TA-TW")
        ToastMessageShow("OSGB Grid Reference Map not HL-HZ/JL-JW/NA-NZ/OA-OW/SA-SZ/TA-TW", True)
        Return False
    End If
    Log("End of ValidateGridRef1")
    Log("OSGB Grid Ref Map OK")
    Return True
End Sub
 
Top