have script to do calc, not perfect help pls

I am writting a script that adds a DVD number to an excel sheet. The DVD number depends on the fileName passed through.

At the moment 80 images are on a dvd. I have a script that does this, gets the dvd number, but if the namber passed is 80 then the returned answer after the script is run is 2, but should be 1. Same on each number that is a multiple of 80.

Help please cheers guys.


on getDVD(fileName)
	--back up the old settings
	set oldDelims to AppleScript's text item delimiters
	try
		--as some files have a * just before the -
		if fileName contains "a*" then
			set AppleScript's text item delimiters to {"a*"}
		else if fileName contains "*" then
			set AppleScript's text item delimiters to {"*"}
		else --cretae new applescript delimiter settings
			set AppleScript's text item delimiters to {"-"}
		end if
		--set number to division by 80, return without decimel
		set num to (((text item 1 of fileName) as number) / 80) div 1
		--set the delimiters back to the original
		set AppleScript's text item delimiters to oldDelims
		--return the value of DVD
		return (num + 1)
	on error theError
		--set applescripts delimiters back to originals
		set AppleScript's text item delimiters to oldDelims
		display dialog "An error occured: " & return & theError buttons {"Cancel"}
	end try
	
end getDVD

the filename format is:
002451-CF.jpg
so 000080-CF.jpg should be 1 but returns 2.

cheers guys

Isn’t this line the one that is causing the problem? If you remove it, does the script behave as desired?

return (num + 1)

– Rob

it is causing the problem but only when the number is 80,160,240,320 etc…

Basically numbers 1-80 are in dvd 1. But with the script and no num +1 then the returned value is 0. So put the + 1 in.

But again as said above if its 80 then the answer should not be 2 but 1 which is what it does.

Does this work?

on getDVD(fileName)
	--back up the old settings 
	set oldDelims to AppleScript's text item delimiters
	try
		--as some files have a * just before the - 
		if fileName contains "a*" then
			set AppleScript's text item delimiters to {"a*"}
		else if fileName contains "*" then
			set AppleScript's text item delimiters to {"*"}
		else --cretae new applescript delimiter settings 
			set AppleScript's text item delimiters to {"-"}
		end if
		--set number to division by 80, return without decimel 
		set num to round (((text item 1 of fileName) as number) / 80) rounding up
		--set the delimiters back to the original 
		set AppleScript's text item delimiters to oldDelims
		--return the value of DVD 
		return num
	on error theError
		--set applescripts delimiters back to originals 
		set AppleScript's text item delimiters to oldDelims
		display dialog "An error occured: " & return & theError buttons {"Cancel"}
	end try
end getDVD

– Rob

yes it does thanks