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
Searching A table for data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Searching A table for data
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
Tom
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Searching A table for data
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Searching A table for data
Hi Tom
Oh I'd forgotten about lineOffset! Here is another way, more verbose (and frankly less elegant) but maybe easier to 'follow along?'
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..."