Problems with incorporating ‘GetValue’-script in Quark script

Hi all,

I am working on a quarkscript to select images, put them on the right place, rename the pic box and text box, but I am having trouble with the last part: putting the right text on the right place.
I have the script to look up the text of the corresponding filenumber, but I am having difficulties in putting this script together with what I have.

I hope there is someone who can put me in the right direction.

This one looks up the specifications from a textfile and returns the specifications.

set fileName to "FR.1.1094.009"

to getValue for currKey from currString
	set o to offset of currKey in currString
	if o is 0 then return "no match"
	first paragraph of currString's text o thru end
end getValue

getValue for fileName from read (choose file)

-->>"FR.1.1094.009	Oor, 1994. 81 x 58,5 cm. potlood, kleurpotlood en pastel op papier"

This is (part of) the script in which it has to be incorparated:

tell application "QuarkXPress Passport"
	tell document 1
		set theCounter to 1
		repeat with n from 1 to count theboxList --Repeat 12 times ('cause there are 12 pic boxes)
			log item 1 of item n of theboxList
			if (item 1 of item n of theboxList) is in SelectedBoxes then
				set thebox to (item 1 of item n of theboxList)
				set theSpecbox to (item 2 of item n of theboxList)
				
				set theImage to (thefolder & item theCounter of picList as Unicode text)
				tell picture box thebox of current page
					--Put image in box.
					set image 1 to theImage as alias
					set selected to true
					set bounds of image 1 to proportional fit
					
					--get filename of the image.
					set filevar to file path of image 1 of it as text
					set fileName to my getfileName(filevar)
					
				end tell
				
				--Rename the boxes to the filename
				set name of picture box thebox of current page to fileName
				set name of text box theSpecbox of current page to fileName
				
				--Get specs
				getValue for fileName from read specsFile
				
				tell text box theSpecbox
					set story 1 to getValue -- Here should be placed the returned result, but doesn't work.
				end tell
				set theCounter to theCounter + 1
			end if
		end repeat
	end tell
end tell


--GetSpecs from file
to getValue for currKey from currString
	set o to offset of currKey in currString
	if o is 0 then return "no match"
	first paragraph of currString's text o thru end
end getValue

--gets name of file from file path
on getfileName(path)
	set pathstr to (path as string)
	set lastColon to (offset of ":" in (reverse of (characters of pathstr)) as string) of pathstr
	return text from -(lastColon - 1) to -5 of pathstr
end getfileName

Thanks (again) Jacques.
I haven’t used these kind of handlers until now. But this works perfect.
Just a small part to go and the script will be ready to make 56 pages with 400 images and texts faultless.

Thanks man.
kjeld