handler

here is what I have in my script that is NOT working

set_tabs(char_count)

here is the handler

on set_tabs(char_count)
	if char_count is less than 14 then
		set the_tabs to tab & tab & tab & tab & tab
	end if
	
	if char_count is greater than 25 then
		set the_tabs to tab & tab
	end if
end set_tabs

If you want to set a variable to the value returned by the handler (either 5 or 2 tabs), then you need to do that. Also, it’s a good idea to do something if the character count is between 14 and 25.

set theReturnedTabs to set_tabs(10)

on set_tabs(char_count)
	if char_count is less than 14 then
		set the_tabs to tab & tab & tab & tab & tab
	else if char_count is greater than 25 then
		set the_tabs to tab & tab
	else
		set the_tabs to ""
	end if
	return the_tabs
end set_tabs

thanks

still not working. here is an update

Applescript:

if file_name contains "_Instrumental_" then
			set AppleScript's text item delimiters to {"_Instrumental"}
			set new_Instrumental_name to text item 1 of file_name
			set AppleScript's text item delimiters to {""}
			set char_count to count characters in new_Instrumental_name
			
			set theReturnedTabs to set_tabs(char_count, the_tabs) -- DOES NOT WORK
			
			set merge_files to merge_files & new_Instrumental_name & theReturnedTabs & "xxx" & return
		end if

My Handler:

-- DOES NOT WORK
on set_tabs(char_count, the_tabs)
	if char_count is less than 18 then
		set the_tabs to tab & tab & tab & tab & tab
	end if
	return the_tabs
end set_tabs

I am at a loss as to the intended purpose of your script. However, paste the following into Script Editor and run the script. It works as written. If this doesn’t do what you want, please explain what you want the script to do.

set file_name to "vocal_Instrumental_music"
set merge_files to "some text_"

if file_name contains "_Instrumental_" then
	set AppleScript's text item delimiters to {"_Instrumental"}
	set new_Instrumental_name to text item 1 of file_name --> vocal
	set AppleScript's text item delimiters to {""}
	set char_count to count characters in new_Instrumental_name --> 5
	
	set theReturnedTabs to set_tabs(char_count) --> "					" 
	
	set merge_files to merge_files & new_Instrumental_name & theReturnedTabs & "xxx" & return
	--> "some text_vocal					xxx
	--> "
end if

on set_tabs(char_count)
	if char_count is less than 18 then
		set the_tabs to tab & tab & tab & tab & tab
	else
		set the_tabs to ""
	end if
	return the_tabs
end set_tabs

not working, here is my screenshot, thanks for trying to help me

https://www.dropbox.com/s/0ewa1zhpcmbwv2n/script.png?dl=0

If you call a handler from within a tell statement, you have to add my or of me:

 set theReturnedTabs to my set_tabs(char_count)

The AppleScript Language Guide explains this:

https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_about_handlers.html#//apple_ref/doc/uid/TP40000983-CH206-DontLinkElementID_249

IT WORKS NOW!!! Thanks. Now I write 1 handler and call it multiple times. Thank you so much