How To pass string from Dialog to Finder command

First off I’m near total noob. I’m trying to modify a couple of snippits and build a frankenstein type script.
I am trying to get the finder to open a folder named after a student username on a windows share called “STUDENTHOME”.

So the dailog asks for username and passes the text string to the finder and tells it to open STUDENTHOME:username:

I just need to figure out how to pass the string from the dialog into the finder comand.

This is what I have so far.

Any suggestions?
Thanks KJ

tell application "Finder"
	activate --bring to front
	set theDialog to display dialog "Please enter your username" default answer "" with icon 1
	set UserInput to the text returned of theDialog
	set ButtonReturned to the button returned of theDialog
	--display dialog UserInput --uncomment to view the result
end tell

--if the user cancelled:
if ButtonReturned = "Cancel" then --the user cancelled
	return --end the script
	--or appropriate handler
end if

repeat
	try
		alias "STUDENTHOME:" -- that is the windows share
		exit repeat
	end try
end repeat
tell application "Finder" to open alias "STUDENTHOME:--DIALOG STRNG GOES HERE:"

This should do it:
(not tested though)

tell application "Finder"
   activate --bring to front
   set theDialog to display dialog "Please enter your username" default answer "" with icon 1
   set UserInput to the text returned of theDialog
   set ButtonReturned to the button returned of theDialog
   --display dialog UserInput --uncomment to view the result
end tell

--if the user cancelled:
if ButtonReturned = "Cancel" then --the user cancelled
   return --end the script
   --or appropriate handler
end if

repeat
   try
       alias "STUDENTHOME:" -- that is the windows share
       exit repeat
   end try
end repeat
tell application "Finder" to open (("STUDENTHOME:"& UserInput&":") as text as alias)

Cheers Vince

Pressing “Cancel” in a display dialog will generate error number -128 (“User canceled.”). Unless you are using try block to catch errors, that should end the script on it’s own. Thus, you can get rid of your if statement:

tell application "Finder"
	activate
	display dialog "Please enter your username:" default answer "" with icon 1
	set UserInput to the text returned of result
end tell

repeat
	try
		alias "STUDENTHOME:"
		exit repeat
	end try
end repeat

tell application "Finder" to open (("STUDENTHOME:" & UserInput & ":") as text as alias)

You two are fantastic. Thanks a bunch for the quick replys.
I have further modified to take two inputs (as I need to drill down two levels).
Here is what it looks like

tell application "Finder"
	activate
	display dialog "Please enter the year you graduate:" default answer "" with icon 1
	set UserInput to the text returned of result
end tell

tell application "Finder"
	activate
	display dialog "Please enter your username:" default answer "" with icon 1
	set UserInput2 to the text returned of result
end tell

repeat
	try
		alias "STUDENTHOME:"
		exit repeat
	end try
end repeat

tell application "Finder" to open (("STUDENTHOME:" & UserInput & ":" & UserInput2 & ":") as text as alias)

You don’t need to activate Finder twice.

tell application "Finder"
	activate

	display dialog "Please enter the year you graduate:" default answer "" with icon 1
	set UserInput to the text returned of result

	display dialog "Please enter your username:" default answer "" with icon 1
	set UserInput2 to the text returned of result
end tell