Page 1 of 1

Searching A table for data

Posted: Fri Apr 18, 2014 12:43 am
by trags3
I have a table with 4 columns. All data is numeric.
I want to put a number in a field called tnumber1 on a card and then search down the first column of the table (on another card) until I get to a line that is >= to tnumber1.
The table field is "sp1"
there are 200 lines in the table.
I have tried a number of things but I am stumped.

Tom

Re: Searching A table for data

Posted: Fri Apr 18, 2014 12:48 am
by trags3
By the way, after I find the appropriate line in the table I want to use the 3 numbers in the other columns in the rest of the app.

Tom

Re: Searching A table for data

Posted: Fri Apr 18, 2014 1:19 am
by FourthWorld
See the lineoffset function in the Dictionary, e.g.:

Code: Select all

function GetLineByFirstCol pSomethingToLookFor, pList
   put lineoffset(cr& pSomethingToLookFor & tab, cr& pList) into tOffset
   return line tOffset of pList
end GetLineByFirstCol

Re: Searching A table for data

Posted: Fri Apr 18, 2014 1:53 am
by dave.kilroy
Hi Tom

Oh I'd forgotten about lineOffset! Here is another way, more verbose (and frankly less elegant) but maybe easier to 'follow along?'

Code: Select all

on searchTable
   put fld tNumber1 into tSearch
   if tSearch is not a number then 
      answer "please enter a valid number"
      exit searchTable
   end if
   
   put fld "sp1" of cd "cdTwo" into tData
   set the itemdel to tab
   
   repeat for each line tRow in tData
      add 1 to tRowNum
      repeat for each item tCell in tRow
         if tCell >= tSearch then
            answer tRow && " was found on row" && tRowNum
            exit searchTable
         end if
      end repeat
   end repeat
end searchTable