_HYPERCARD DATABASE TUNING_ by Jeff Elliott [LISTING ONE] -- insertLink: Subroutine for Link. Links this card into the chain, both -- forwards and backwards. Does not modify the index. -- Arguments: -- root card id of the first card in the chain -- linkf name of the bg field on this card that holds the links -- n line number for links in linkf -- i item number for FORWARD link in line n -- returns: 0: noErr, -1: no forward link, -2: no back link function insertLink root,linkf,n,i -- BACKWARD link always follows FORWARD link as the next item in line n of field linkf put i + 1 into j put the short ID of this card into myself put item i of line n of field linkf of card id root into forward -- set vars; who was the put item j of line n of field linkf of card id root into backward -- root pointing to? if there is not a card id forward then return -1 if there is not a card id backward then return -2 put myself into item j of line n of field linkf of card id root -- root's back is always myself if forward is myself then -- it's just the 2nd card put myself into item i of line n of field linkf of card id root -- so my forward is also root else -- no more root changes put myself into item i of line n of field linkf of card id backward -- his forward is me end if -- finally, make links for myself put backward into item j of line n of field linkf -- my back is previously oldest put root into item i of line n of field linkf -- my next card is the root return 0 end insertLink -- Link: called from the card that's being linked. Before a link is added, -- we must first lookup the name in the index. If this name isn't found, -- then we create an index entry. Otherwise, we link this card to the others. -- Expects: card "index" with background field "hiddenIndex" and card field -- "index" -- Arguments: name, string to lookup in (or add to) the index; -- linkf, n, and i are the same as for subroutine insertLink. -- returns: a success or failure message function link name, linkf, n, i put the short ID of this card into myself go card "index" find whole name in field "hiddenIndex" -- is this name in the index? if the result is "not found" then -- no, so add it to index -- first in the link, so create index entries -- format for hiddenIndex: string, card ID, count get the number of lines in field "hiddenIndex" put name & "," & myself & "," & 1 B into line it + 1 of field "hiddenIndex" -- tack it onto the end -- card field index only has the strings get the number of lines in cd field "index" put name into line it + 1 of cd field "index" sort cd field "index" -- make it pretty go back -- as the only card, it is just linked to itself put myself & "," & myself into line n of field linkf else -- the name's in the index, so we link to other cards add 1 to item 3 of line word 2 of the foundline B of field "hiddenIndex" -- increase link count in index put item 2 of the value of the foundline into root go back -- return to card being linked -- we're ready to link up with the other cards if insertLink (root,linkf,n,i) is not 0 then return "The links are damaged or missing." -- error exit end if end if return "Link successful." -- everything OK, normal exit end link [LISTING TWO] on mouseUp -- works only in HyperCard 2.0 or later find whole the value of B the clickline in field "hiddenIndex" go card ID item 2 of B the value of the foundLine end mouseUp [LISTING THREE] on mouseUp ask "Name to add:" if it is not empty then doMenu "New Card" put it into fld "myName" put link (it,"links",1,1) end if end mouseUp