Looking fine so far.
Initially I was trying to "produce" a Map file myself and place it in the path that will be passed for reading the Map from file. All OK except the order of the Keys that were imported from the file are not same like in the file.
I think I might got it wrong that the keys/values pairs listed on each line in a file can be addressed say by line number(or index if you like) after importing them with File.ReadMap .
On the other hand if I only use Map.Put(key,val) to add elements in my declared Map I can though address them by their index as in the "LookupTable" sub below, and I get the results as expected.
Anyways, if I comment the line:
Map1 = File.ReadMap(fPath,filename)
I can use the "LookupTable" sub below for searching in the declared Map which is initialized at first Activity_Create then populated with the 500 about key/value pairs at run time (which takes a few seconds though).
Sub LookupTable(parameter_value As Double) ' the value that we will be searching by in column 1
Dim fPath As String : fPath=File.DirDefaultExternal
Dim filename As String : filename="searchtables.ini"
Dim lookup_pre, lookup_post As Double
'Dim lookup_vector, result_vector As Double ' declared in Sub Process_Globals
'Map1.Initialize executed at Activity_Create(Firstime as Boolean)
'
Map1 = File.ReadMap(fPath,filename) ' import the Map values from external storage
'
lookup_value = parameter_value ' pas the parameter value to the variable
Log("lookup_val = "& lookup_value&" "¶meter_value) ' debug line
Log("table size: "&Map1.Size) ' debug line
For i = 0 To Map1.Size - 1 ' begin searching the table
lookup_vector = Map1.GetKeyAt(i) ' the Map key at position (i)
Log("index:"&i&" lookup_vector : "&lookup_vector) ' debug line
If lookup_vector >= lookup_value Then ' look for value greater than lookup_value (column 1)
Log("greater value showed up at row:"& i) ' debug line
lookup_post = lookup_vector - lookup_value ' diff to upper value
lookup_pre = Map1.GetKeyAt(i-1) ' previous value
lookup_pre = lookup_value - lookup_pre ' diff to lower value
If lookup_post > lookup_pre Then ' now check which one is smaller (closer to lookup_value)
result_vector = Map1.GetValueAt(i) ' and
Else ' return the respective Key Value
result_vector = Map1.GetValueAt(i-1) ' accordingly
End If
Exit ' exit this loop
End If
Next
End Sub
I will try approaching also via SQL using the Cursor.Position example to get my values.