Make a text variable a number?

I know this is probably a stupid question but I can’t seem to get my text variable to be a number variable. Here’s my silly try at it:


	display dialog "Set the max dimension of new images (in pixels):" default answer "1000"
	set the_size to the text returned of the result
	set the_size to the_size as number
	if the_size is not number then
		display dialog "Entered text was not a number, so the max dimension has been set to 1000 pixels." with icon note giving up after 30
	end if

Help appreciated!

Hi,

try this


repeat
	display dialog "Set the max dimension of new images (in pixels):" default answer "1000"
	try
		set the_size to the text returned of the result as integer
		exit repeat
	on error
		display dialog "Entered text was not a number, so the max dimension has been set to 1000 pixels." & ¬
			return & "Try it again!" with icon note giving up after 3
	end try
end repeat

You could check the class of the variable:

display dialog "Set the max dimension of new images (in pixels):" default answer "1000"
set the_size to the (text returned of the result) as text
if (class of the_size) is string then
	display dialog "Entered text was not a number, so the max dimension has been set to 1000 pixels." with icon note giving up after 30
	
end if
set the_size to the_size as number
if (class of the_size) is string then
	display dialog "Entered text was not a number, so the max dimension has been set to 1000 pixels." with icon note giving up after 30
else
	display dialog "Entered text is now a number: " & the_size
end if

Thanks, you guys are fantastic.