killwindow utilizing a loop

Hi, I wrote the following procedure to delete all the subwindows in a window named "Panel". The names of the subwindows are like "Panel#G0", "Panel#G1"...
When i run the procedure, the pop-up window appears "window while executing KillWindow, the following error occured: Expected window name".
I am quite confused with this error, so how can i handle with this problem?
Thanks in advance for help!

function button_clear(ctrl):Buttoncontrol
  string ctrl
  variable subwinnum
  variable i
  string/g childlist
  string subwn, subwnname
  childlist=Childwindowlist("Panel")
  subwinnum=ItemsInList(childlist)
  for(i=0; i
Also subwn isn't being incrementing. Move the sprintf inside the for loop or use something like the following.


  for(i=0; i<subwinnum; i+=1)
    subwnname="Panel#G"+num2str(i)
    killwindow subwnname
  endfor


Finally, the statement
subwinnum=ItemsInList(childlist)-1


should be
subwinnum=ItemsInList(childlist)
This version works:


function button_clear(ctrl):Buttoncontrol
	string ctrl

	String panel= WinName(0,64)	// top panel
	String childlist=Childwindowlist(panel)
	Print childlist
	variable subwinnum=ItemsInList(childlist)
	variable i
	for(i=0; i<subwinnum; i+=1) 
		String subwnname= panel+"#"+StringFromList(i,childList)
		killwindow $subwnname
	endfor
	KillWaves/A/Z/F
end

--Jim Prouty
Software Engineer, WaveMetrics, Inc.