Problems trying to open more than 1 file

Im having this message when i try to open more than 1 file in my lotusscript agent:

File already open (in the last line of the following code)

The names of the files are diferent!!

My code:

Dim fileControl As Integer

Dim fileNum As Integer

Dim file1 As Integer

Dim file2 As Integer

file1% = Freefile()

file2% = Freefile()







	fileName$ = nomearquivoSolicitacaoVIAGEM & ".xml"

	fileControl = 2

	nomeArquivo = fullpath & nomearquivoSolicitacaoVIAGEM

	OutputFile1 = nomearquivoSolicitacaoVIAGEM & ".xml"

	FileExists = Dir$( OutputFile1, 0 )

	While FileExists <> "" 

		OutputFile1 = nomearquivoSolicitacaoVIAGEM & " (" & fileControl & ").xml"

		FileExists = Dir$( OutputFile1, 0 )

		fileControl = fileControl + 1

	Wend

	Open OutputFile1 For Output As file1%

	

	fileName$ = nomearquivoPrestacaoVIAGEM & ".xml"

	fileControl = 2

	nomeArquivo = fullpath & nomearquivoPrestacaoVIAGEM

	OutputFile2 = nomearquivoPrestacaoVIAGEM & ".xml"

	FileExists = Dir$( OutputFile2, 0 )

	While FileExists <> "" 

		OutputFile2 = nomearquivoPrestacaoVIAGEM & " (" & fileControl & ").xml"

		FileExists = Dir$( OutputFile2, 0 )

		fileControl = fileControl + 1

	Wend

	Open OutputFile2 For Output As file2%

Any ideas? Thanks =)

Subject: Problems trying to open more than 1 file

I’d lean toward the problem having to do with files being left open.Try using FreeFile() for consistent new values and forcing a close # when completed.

Collin

KC8TKA