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