Searching A table for data

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Searching A table for data

Post by trags3 » Fri Apr 18, 2014 12:43 am

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

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Searching A table for data

Post by trags3 » Fri Apr 18, 2014 12:48 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Searching A table for data

Post by FourthWorld » Fri Apr 18, 2014 1:19 am

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Searching A table for data

Post by dave.kilroy » Fri Apr 18, 2014 1:53 am

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
"...this is not the code you are looking for..."

Post Reply