handler error when copy to end of

I am just getting into learning handlers and I need some help, Its probably something very simple I am doing wrong

here is the script


set AppleScript's text item delimiters to {""}
on get_number(number_routine, item_a, item_b)
	
	repeat with i in items item_a thru item_b of number_routine
		set AppleScript's text item delimiters to ","
		set x to text items of i
		set number_i_want to item 5 of x
		copy number_i_want to end of number_i_want_list
	end repeat
	return number_i_want_list
end get_number

set AppleScript's text item delimiters to {""}
set x to {"Date, Time, Open, High, Low, Close, Volume, OI", "2000-08-04, 00:00:00, 3.82, 4.77, 3.58, 3.73, 157393, 0", "2000-08-07, 00:00:00, 4.02, 4.02, 3.73, 3.88, 32246, 0"}


set result to get_number(x, 1, 2)
result

and I am told
error “The variable number_i_want_list is not defined.” number -2753 from “number_i_want_list”

any thoughts
thanks

Hi,

the error message tells the truth: lists must be defined by setting them to an empty list {} .
It’s recommended to put custom handlers after the main code “ which is actually the run handler


set x to {"Date, Time, Open, High, Low, Close, Volume, OI", "2000-08-04, 00:00:00, 3.82, 4.77, 3.58, 3.73, 157393, 0", "2000-08-07, 00:00:00, 4.02, 4.02, 3.73, 3.88, 32246, 0"}
set theResult to get_number(x, 1, 2)
theResult

on get_number(number_routine, item_a, item_b)
	set number_i_want_list to {}
	set {TID, text item delimiters} to {text item delimiters, ","}
	repeat with i in items item_a thru item_b of number_routine
		set x to text items of i
		set number_i_want to item 5 of x
		copy number_i_want to end of number_i_want_list
	end repeat
	set text item delimiters to TID
	return number_i_want_list
end get_number

Thanks,
your a legend

I’m curious – why?

Just for readability