How to create a list of the 40 first item of a folder

I need a clue…
I can’t make a list of the item 1 of a folder to the 40th item of this folder
I know how to list the first, the last or the 40th item of a folder but I need to limit the size of my selection because applescript tell me that he is out of memory.

Script

set x to every items of folder y whose file type is “JPEG”

result = “Out of memory”

so I try

set x to (the first item of folder y to the 40th item of folder y)
result = "to:40th item of folder y can’t go after the first item of folder

Qu’est ce que je peux faire avec cette merde :!: (In english: Wha cound I do with this s…)

set theFolder to choose folder
tell application "Finder"
	if (count of items of folder theFolder) is not less than 40 then
		set x to (items 1 through 40) of (list folder theFolder)
	end if
end tell

or

set theFolder to choose folder
tell application "Finder"
	if (count of items of folder theFolder) is not less than 40 then
		set x to (items 1 through 40) of (every item of folder theFolder)
	end if
end tell