I've been working on some code that needs to sort measurements as doubles. I am forced to use a bunch of If..Then statements to figure out which bucket the value goes into. It works but it just looks bad. What would be nice is to use a Select...Case structure but I would have to call out every value. It sure would be nice if I could use:
B4X:
Dim a As Double
a=1.72341
Select a
Case 0 to 2
Log ("A")
Case 2 to 4
Log ("B")
Case Else
Log ("C")
End Select
a simple list will not work in your case; you are right... But with a LIST of MAPs it should be easy possible to get the right one in one loop through the list of maps...
A map or a custom TYPE should work...
Not a solution. More my thoughts of creating the list
B4X:
Dim checklist As List
checklist.Initialize
Dim m As Map = CreateMap("min": 0, "max": 2, "out": "A")
checklist.Add(m)
Dim m As Map = CreateMap("min": 2, "max": 4, "out": "B")
checklist.Add(m)
Dim m As Map = CreateMap("min": 4, "max": 6, "out": "C")
checklist.Add(m)
And then a sub which will iterate through this list of maps to find the matching "out" for a given double
Sub check(value As Double) As String
Dim out As String=""
For i = 0 To checklist.Size-1
Dim m As Map = checklist.Get(i)
If m.Get("min") < value AND m.Get("max") >= value Then
Return m.Get("out")
End If
Next
End Sub