RequestFile gives up!

BlitzPlus Forums/BlitzPlus Programming/RequestFile gives up!

I have a problem with RequestFile.

I wouldn't normally write so much code but im not sure which part is messing up the rest so i'm gonna have to.

Function createAddWindow(parent%, parentIPath$)		;CREATES A WINDOW FOR THE USER TO ADD A NEW DIRECTORY OR FILE 

	addWin = CreateWindow("Add", ClientWidth(Desktop())/2-170, ClientHeight(Desktop())/2-102.5, 300, 205, window, 1)
	addPanel = CreatePanel(0, 0, ClientWidth(addWin), ClientHeight(addWin), addWin)
	rdoAFile = CreateButton("File", ClientWidth(addPanel)/4-20, 10, 40, 20, addPanel, 3)
	rdoADir = CreateButton("Dir", ClientWidth(addPanel)/4*2-20, 10, 40, 20, addPanel, 3)
	SetButtonState rdoAFile, 1
	lblName = CreateLabel("File Name:", 10, 40, 100, 20, addPanel)
	lblPath = CreateLabel("File Path:", 10, 70, 100, 20, addPanel)
	txtAName = CreateTextField(110, 40, 170, 20, addPanel)
	txtAPath = CreateTextField(110, 70, 170, 20, addPanel)
	btnAddBrowse = CreateButton("Browse", ClientWidth(addPanel)-93, 100, 80, 20, addPanel)
	chkAHid = CreateButton("Hidden", 30, 100, 100, 20, addPanel, 2)
	chkARdo = CreateButton("Read Only", 30, 120, 100, 20, addPanel, 2)
	btnCompAdd = CreateButton("Add", ClientWidth(addPanel)/2-83.5, 145, 80, 20, addPanel)
	btnAddCan = CreateButton("Cancel", ClientWidth(addPanel)/2+3.5, 145, 80, 20, addPanel)	
	
	While WaitEvent()
		If EventID() = $401
			If EventSource() = rdoAFile Or EventSource() = rdoADir Or EventSource() = rdoUnin
				If ButtonState(rdoAFile) = 1
					SetGadgetText lblName, "File Name:"
					SetGadgetText lblPath, "File Path:"
					EnableGadget lblPath
					EnableGadget txtAPath
					EnableGadget chkAHid
					EnableGadget chkARdo
					EnableGadget btnAddBrowse
					SetGadgetText txtAPath, ""
				Else If ButtonState(rdoADir) = 1
					SetGadgetText lblName, "Directory Name:"
					SetGadgetText lblPath, "Directory Path:"
					DisableGadget lblPath
					DisableGadget txtAPath
					EnableGadget chkAHid
					EnableGadget chkARdo
					DisableGadget btnAddBrowse
					SetGadgetText txtAPath, "n/a"
				End If
			End If
				
			If EventSource() = btnCompAdd
				If TextFieldText(txtAName) = "" Or TextFieldText(txtAPath) = ""
					Notify "Please fill in all the text fields."
				Else
					f.file = New file
					If ButtonState(rdoAFile) = 1
						f\typeFile% = 1
						endChr$ = ""
						iconNum% = 1
					Else
						f\typeFile% = 2
						endChr$ = ""
						iconNum% = 0
					End If
					f\name$ = TextFieldText(txtAName)
					f\ID% = AddTreeViewNode(f\name$, parent%, iconNum%)
					f\path$ = TextFieldText(txtAPath)
					f\iPath$ = parentIPath$ + f\name$ + endChr$
					f\hidden% = ButtonState(chkAHid)
					f\readonly% = ButtonState(chkARdo)
					ExpandTreeViewNode parent%
					FreeGadget addWin
					Return
				End If
			End If
			If EventSource() = btnAddCan
				FreeGadget addWin
				Return
			End If
			If EventSource() = btnAddBrowse
				fileR$ = RequestFile("Add File:", "")
				If fileR$ > ""
					Repeat
						pos% = Instr(fileR$, "", oldPos% + 1)
						If pos% = 0
							pos% = oldPos%
							Exit
						Else
							oldPos% = pos%
						End If
					Forever
					length% = Len(fileR$)
					fileName$ = Mid(fileR$, pos%+1, length%-pos%)
					SetGadgetText txtAName, fileName$
					SetGadgetText txtAPath, fileR$
				Else
					Notify ""
				End If
			End If
		End If
		If EventID() = $803
			Exit
		End If
	Wend
	FreeGadget addWin
	Return
		
End Function


I did a bit of editing so it may look a bit wierd! Anyhoo, i can run this and to my TreeView i add with the browse button:

A file;
A dir;
A file;
A file;
A dir;
A dir;

but when i go to add the next file (and annoyingly my last) it just notifies "You didn't select a file". I don't thnik it matters how i add the files or how many i add. Is there anything wrong with the code that would make it cause an error with RequestFile?

Thanks to anyone who can help.

This might have something to do with it (I haven't really looked at your code though) :
http://www.blitzbasic.com/Community/posts.php?topic=36532

Thanks for that i'll have a look but i also found out that it works 5 times and on the 6th it goes Bleh (not literally)!

I tried some more testing and it only happens when it's compiled. And the code missed out
fileR$ = Requestfile("Add:", "")

altogether.