I have only recently discovered LiveCode while doing a search for a simple cross platform development environment for a class project. Having had experience with Hypercard I was quite happy to learn that this is built on the same paradigms. Here is my current problem:
I am trying to implement a text field as a search box to filter the columns in a Data Grid. Reading through the forum I learned about a useful example in a file called Summer Academy '11 Index. It is exactly the search implementation I was hoping for. Well, kind of. It appears that the Summer Academy Index file populates it's Data Grid from an external text file. I do not need to do this. My Data Grid contains content entered through the Inspector. What I've found as I've tried to use their code in my stack is that upon doing a search my actual content is overridden by their source file. So what I need to do is figure out the necessary code to tell the search to work from the data that's already in the grid and not to reference an external text file.
The Summer Academy stack had search-related code in only two places; the Stack Script and the Script on the search field. In my stack I have copied the code from their search field verbatim because it seems to fit my needs without modification, but the Stack Script has me very confused. I do not understand the LiveCode language well enough (yet) to figure out how to remove the code that searches for the external text file. I need to tell it instead to search based on the that's already in the Data Grid. For the benefit of all of you who are smarter than me, here is the code from the Summer Academy Stack Script:
Code: Select all
global theData
-- SA '11 Index Stack by Mark Smith, Version 1.01 -- July 30, 2011
on preopenstack
## Read the Summer Academy Index in from a tab delimited text file into a custom property
## this file was created from exporting an Excel file using the tab delimited file option
## if this file does not exist on disk it may be in a stack custom property: cindex
put "/users/mark/runrev/summer academy" & "/sa index.txt" into tSavePath
if there is a file tSavePath then
-- answer "File found"
set the dgText of group "DataGrid" to empty -- empty the datagrid control
put url ("file:" & tSavePath) into theData
cleanupsaindex -- cleanup the index
put false into firstLineContainsColumnNames
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid" to theData
set the cindex of this stack to theData -- copy the data into a custom property for later access
-- i.e. I can distribute the stack with the custom property
else
-- answer "File not found"
put the cindex of this stack into theData -- copy the custom property into a field
set the dgText of group "DataGrid" to empty -- empty the datagrid control
put false into firstLineContainsColumnNames
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid" to theData
end if
put the number of lines of thedata into thecount
put thecount && "records" into fld "count"
end preopenstack
on cleanupsaindex
-- first, strip leading/trailing quotes from the topic field, excel added these
set itemdelimiter to tab
put empty into thecopy -- prepare to copy the data
repeat for each line tLine in thedata -- thanks mwieder
put item 1 of tline into ttopic -- check each topic entry
put item 2 of tline into tsource
put item 3 of tline into tlocation
if ttopic begins with quote then -- if a leading quote is found
put char 2 to -2 of ttopic into ttopic -- trim first and last char
end if
if ttopic is not empty then
put ttopic & tab & tsource & tab & tlocation & return after thecopy -- rebuild the line in thecopy
end if
end repeat
put thecopy into thedata -- copy the filtered version back
-- here are a couple more cleanup tasks
replace quote & quote with quote in thedata -- replace double quotes with single quotes
replace ":30:00" with ":30" in theData -- trimming the hundredths of seconds
replace ":00:00" with ":00" in theData -- trimming the hundredths of seconds
replace "Ó" with quote in theData -- replacing wonky trailing quote chars
replace "Ò" with quote in theData -- replace wonky leading quote chars
end cleanupsaindex
Code: Select all
on rawkeyup
put fld "search" into tsearch
put the cindex of this stack into thecopy
filter thecopy with "*" & tsearch & "*"
put false into firstLineContainsColumnNames
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid" to thecopy
put the number of lines in thecopy into thecount
put thecount && "records" into fld "count"
end rawkeyup
on returninfield
-- just ignore it
end returninfield

I hope someone can come to my rescue on this. My wall is beginning to dent from having my head smashed against it so often.