Forum > General
File not open??? Why?
OC DelGuy:
I just wrote this procedure Why is the file "Not Open"?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Procedure WriteVillagedata; // This will write the Data Structure to file. Var x, y : Integer; Begin Assignfile(FilenameOut, 'VillageData.txt'); Try ReWrite(FilenameOut); For x := 1 to recds do Begin WriteLn(FilenameOut, Villages[x].Name); This is line 60 as referred to in the error message. WriteLn(FilenameOut, Villages[x].Inn); WriteLn(FilenameOut, Villages[x].Government); WriteLn(FilenameOut, Villages[x].Population); WriteLn(FilenameOut, Villages[x].Families); WriteLn(FilenameOut, Villages[x].Farmers); WriteLn(FilenameOut, Villages[x].Artisans); WriteLn(FilenameOut, Villages[x].Laborers); WriteLn(FilenameOut, Villages[x].Paupers); For y := 1 to 3 do Begin WriteLn(FilenameOut, Villages[x].Gods[y]); WriteLn(FilenameOut, Villages[x].Taverns[y]); WriteLn(FilenameOut, Villages[x].Trade[y]); end; {For y} Close(FilenameOut); End; {For x} finally end; {Try} end; {Proc WriteVillagedata}
KodeZwerg:
Try not to close the file in your loop, does it help?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Procedure WriteVillagedata; // This will write the Data Structure to file. Var x, y : Integer; FilenameOut: TextFile; Begin Assignfile(FilenameOut, 'VillageData.txt'); Try ReWrite(FilenameOut); For x := 1 to recds do Begin WriteLn(FilenameOut, Villages[x].Name); This is line 60 as referred to in the error message. WriteLn(FilenameOut, Villages[x].Inn); WriteLn(FilenameOut, Villages[x].Government); WriteLn(FilenameOut, Villages[x].Population); WriteLn(FilenameOut, Villages[x].Families); WriteLn(FilenameOut, Villages[x].Farmers); WriteLn(FilenameOut, Villages[x].Artisans); WriteLn(FilenameOut, Villages[x].Laborers); WriteLn(FilenameOut, Villages[x].Paupers); For y := 1 to 3 do Begin WriteLn(FilenameOut, Villages[x].Gods[y]); WriteLn(FilenameOut, Villages[x].Taverns[y]); WriteLn(FilenameOut, Villages[x].Trade[y]); end; {For y} End; {For x} finally Close(FilenameOut); end; {Try} end; {Proc WriteVillagedata}
jamie:
Assign(...) instead of AssignFile?
Bogen85:
--- Quote from: jamie on January 31, 2023, 03:41:26 am ---Assign(...) instead of AssignFile?
--- End quote ---
That is fine.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program wvd;{$mode objfpc} Procedure WriteVillagedata; // This will write the Data Structure to file. Var x, y : Integer; FilenameOut: textfile; Begin Assignfile(FilenameOut, 'VillageData.txt'); Try ReWrite(FilenameOut); writeln(FilenameOut, 'text'); finally close(FilenameOut); end; {Try} end; {Proc WriteVillagedata} begin WriteVillagedata;end.
The above works, @KodeZwerg likely caught the problem, the close file being in the loop.
KodeZwerg:
Maybe also his "FilenameOut" is wrong, since he not show, I added that on my own as local.
Navigation
[0] Message Index
[#] Next page