difference between script and program

I have a script to search by name and extension

in the script editor it works, when I save it as a program, it does not work.
error is ‘some object not found’

I do not know whats wrong

set theName to quoted form of text returned of (display dialog "nach Name suchen" default answer "" buttons {"Abbrechen", "Weiter!"} default button 2)
if result is "weiter!" then return
set theext to quoted form of text returned of (display dialog "Extension" default answer "" buttons {"Abbrechen", "Suchen!"} default button 2)
if result is "Suchen!" then return
set thefolders to {""}
set founditems to {}
repeat with i in thefolders
	set thepath to ({"Axel_1", "/"} & (i as string) as string) --as alias
	--tell application "System Events" to exists thepath
	--if result is true then
	set command to "mdfind 'kMDItemDisplayName == " & quote & theName & "*" & quote & "wc" & " && (kMDItemFSName == " & quote & "*." & theext & quote & ")'"
	set founditems to founditems & (paragraphs of (do shell script command))
	--end if
end repeat
repeat with i in founditems
	set i to i as string
	set thesize to size of (get info for (POSIX file i))
	set thekind to kind of (get info for (POSIX file i))
	set theName to displayed name of (get info for (POSIX file i))
	set dialog to "Name: \"" & theName & "\"" & return & return & "Typ: " & thekind & return & return & "Größe: " & thesize & " bytes" & return & return & "Pfad: " & i
	set button to button returned of (display dialog dialog buttons {"Schließen", "Öffnen", "Nächstes"} cancel button {"Schließen"} default button {"Nächstes"} with title "Suche nach \"" & theName)
	if button is "Öffnen" then
		try
			set theapp to default application of (get info for (POSIX file i)) as string
			tell application theapp to activate
			tell application theapp to open (POSIX file i as string)
		on error e
			display dialog "Fehler beim Öffnen der Datei:" & return & return & e buttons {"OK"} default button 1
		end try
		--exit repeat
	end if
end repeat

theApp is not defined I think.

Edited: no that’s not it.

Hi Axel, welcome to MacScripter.

We’d like to see the entire error, and if possible, when & where it occurred.
I have not bothered to figure that out, as I saw various wrongnesses in the script…
I’ve put in comments to explain:

# removed quoting, and corrected erroneous handling of dialog result
# you're not dealing correctly with the dialog result; 'theName' suggests its content is a name (=plain text), which it isn't
# also, the original code does not allow stopping the script, which seems to be intended
# the dialog result is a record with 2 properties
set {theName, theResponse} to {text returned, button returned} of (display dialog "nach Name suchen" default answer "" buttons {"Abbrechen", "Weiter!"} default button 2)

# this did not work as intended
# it should end the script when "Weiter!" was pressed, but it does not
# cause of the problem:
# 'result' by itself is the result of the last operation , which was NOT displaying a dialog
if theResponse is "Abbrechen" then return -- now ends upon "Abbrechen", which is the intended result, right?

# quoting an extension isn't very useful
set {theext, theResponse} to {text returned, button returned} of (display dialog "Extension" default answer "" buttons {"Abbrechen", "Suchen!"} default button 2)
if theResponse is "Abbrechen" then return

set thefolders to {} # empty string is redundant when declaring list variable
set founditems to {}

# what's this? 'thefolders' is empty, and 'thepath' is never used.
repeat with i in thefolders
	set thepath to ({"Axel_1", "/"} & (i as string) as string) --as alias
	# why was this commented out?
	--tell application "System Events" to exists thepath
	--if result is true then
	# searching entire drive not recommended
	# look at '-onlyin' qualifier in mdfind manpage
	# you're quoting stuff that was already quoted (before I removed the quoting)
	set command to "mdfind 'kMDItemDisplayName == " & quote & theName & "*" & quote & "wc" & " && (kMDItemFSName == " & quote & "*." & theext & quote & ")'"
	# this is a bit faster than previous wording
	set end of founditems to paragraphs of (do shell script command)
	--end if
end repeat

repeat with i in founditems
	set i to i as string
	# 'info for' is deprecated, which means it'll stop working, without warning, in a future update
	# use System Events to get the meta you need
	set thesize to size of (get info for (POSIX file i))
	set thekind to kind of (get info for (POSIX file i))
	set theName to displayed name of (get info for (POSIX file i))
	
	# removed code for brevity
	
end repeat

Now let’s see if this performs any better - tell us how it goes.

your code quits after second textfield

got it working with this

set myicon to "Mountain:Users:Axel:Documents:icon1.icns"
set theName to quoted form of text returned of (display dialog "nach Name suchen" default answer "" buttons {"Abbrechen", "Weiter!"} default button 2 with icon file myicon)
if result is "Weiter!" then return
set theext to quoted form of text returned of (display dialog "Extension" default answer "" buttons {"Abbrechen", "Suchen!"} default button 2 with icon file myicon)
if result is "Suchen!" then return
set thefolders to {"*"}
set founditems to {}
repeat with i in thefolders
	set thepath to ({""} & (i as string) as string) --as alias
	set command to "mdfind 'kMDItemDisplayName == " & quote & theName & "*" & quote & "wc" & " && (kMDItemFSName == " & quote & "*." & theext & quote & ")'"
	set founditems to founditems & (paragraphs of (do shell script command))
end repeat
repeat with i in founditems
	set i to i as string
	set thesize to size of (get info for (POSIX file i))
	set thekind to kind of (get info for (POSIX file i))
	set theName to displayed name of (get info for (POSIX file i))
	set dialog to "Name: \"" & theName & "\"" & return & return & "Typ: " & thekind & return & return & "Größe: " & thesize & " bytes" & return & return & "Pfad: " & i
	set button to button returned of (display dialog dialog buttons {"Beenden", "Öffnen", "Nächstes"} cancel button {"Beenden"} default button {"Nächstes"} with title "Suche nach \"" & theName with icon file myicon)
	if button is "Öffnen" then
		try
			set theapp to default application of (get info for (POSIX file i)) as string
			set myfile to quoted form of the POSIX path of (POSIX file i as string)
			do shell script "open " & myfile
			delay 0.5
			tell me to activate
		on error e
			display dialog "Fehler beim Öffnen der Datei:" & return & return & e buttons {"OK"} default button 1 with icon file myicon
		end try
	else if button is "Beenden" then
		tell me to quit
	end if
end repeat
set theName to quoted form of text returned of (display dialog "nach Name suchen" default answer "" buttons {"Abbrechen", "Weiter!"} default button 2)

This sets result to whatever is stored in theName

if result is "Weiter!" then return

— so this test will ALWAYS yield false, and the script will never terminate (which is the only function of this line).
Why is this line in the script?

And please provide the full error, and when/where it occurs.

My code “quits after 2nd textfield”, because it is not complete, and was not intended to be complete.

there is no error anymore

it works with the code from Post #4