Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey everyone!, Major question here that has been annoying me, Reason being is my code worked and now its stopped, It was rather spontaneous, The program works, as in the data is stored on the clipboard, But it doesnt write the text files

Delphi
procedure TForm1.BtnSaveClick(Sender: TObject);
var
  F, E: TextFile;
  sName, sSur, sEmail, sTelKid, sMom, sDad, sTelMom, sTelDad, sLs, sSchool, sSchoolTel, sSchoolEmail: String;
begin
  sName:=EdtName.text;
  sSur:=EdtSur.text;
  sEmail:=EdtEmail.text;
  sTelKid:=EdtTelKid.text;
  sTelMom:=EdtTelMom.text;
  sTelDad:=EdtTelDad.text;
  sSchool:=EdtSchool.Text;
  sSchoolTel:=EdtSchoolTel.Text;
  sSchoolEmail:=EdtSchoolEmail.Text;
  sMom:=EdtMum.Text;
  sDad:=EdtDad.Text;
  sLs:=ClevelS.Text;
  AssignFile(E, 'Config\list.txt');
  append(E);
  Writeln(E,sName + ' ' + sSur);
  CloseFile(E);
  CBSearch.Items.LoadFromFile('Config\list.txt');
  CBSearch.Items.SaveToFile('Config\list.txt');
  AssignFile(F, 'Students\' +sName+ ' ' +sSur+ '.txt');
  Rewrite(F);
  WriteLn(F, '  ' +sSchool);
  WriteLn(F);
  WriteLn(F, '  Correo Electronico: ' +sSchoolEmail);
  WriteLn(F);
  WriteLn(F, '  Numero de telefono: ' +sSchoolTel);
  WriteLn(F);
  WriteLn(F, '_____________________________________________________________');
  WriteLn(F, '_____________________________________________________________');
  WriteLn(F);
  WriteLn(F, '  NOMBRE: ' +sName);
  WriteLn(F);
  WriteLn(F, '  APPELIDOS: ' +sSur);
  WriteLn(F);
  WriteLn(F, '  EMAIL: ' +sEmail);
  WriteLn(F);
  WriteLn(F, '  TELEFONO DE ESTUDIANTE: ' +sTelKid);
  WriteLn(F);
  WriteLn(F, '  TELEFONO DE '+sMom+' : ' +sTelMom);
  WriteLn(F);
  WriteLn(F, '  TELEFONO DE '+sDad+' : ' +sTelDad);
  WriteLn(F);
  WriteLn(F, '  NIVEL DE LENGUAGE: ' +sLs);
  CloseFile(F);
  imgStudent.Picture.SaveToFile('Data\'+sName+' '+sSur+'.jpg');
end; 


What I have tried:

It was working then it stopped. I dont know what else to say...
Posted
Updated 9-Sep-16 11:12am
Comments
[no name] 9-Sep-16 19:52pm    
Don't you have a teacher, whose job it is to teach you this, that you can ask for help with your homework assignment? We can't teach you programming question by question.

Quote:
Reason being is my code worked and now its stopped, It was rather spontaneous, The program works, as in the data is stored on the clipboard, But it doesnt write the text files
If it was working and stopped, it is linked to the data, use the debugger to see what is going on.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
v2
Given that it was working and now it stopped. I take that as nothing was changed to the code.

This seems like a repost as i even recognize the code. What help did you get last time?

I'm pretty sure you got told "doesn't write to file" isn't exactly a great description of the problem.

Suggestions:

Are you getting any error messages/exceptions? Does the location you are trying to right to file exist? Does your application have the rights to write to wherever it is attempting to?

If the code didn't change you probably should think that there are external factors on your computer that affect your issue. Given that, we can't really help with those as we can't see your computer.

But to more than likely repeat the answer you were given before.

CBSearch.Items.SaveToFile('Config\list.txt');

That Config directory probably doesn't exist. Other than that, there isn't much else to say.

http://www.codeproject.com/Questions/1125178/Delphi-problems-with-text-files[^]
 
Share this answer
 
v3
Comments
Crytach Daiguren 9-Sep-16 17:15pm    
Ok firstly the repost is because Im battling with multiple parts of this code... this code is my code, anyways what my problem is that the assignfile(F, 'Students\..... etc) is not creating a 'student name.txt' in the subfolder Students... their are no errors, there are no exceptions, its all smooth sailing, it just does not create the text files when it is supposed to
David_Wimbley 9-Sep-16 17:25pm    
Then i suggest you refer to ppolymorphe's Solution 2 as we cannot debug this code for you. Given that you say it was working and not it wasn't this going to turn into a case of "it works on my machine" which isn't helpful for anyone.

Basically, there isn't much we can do until your use your debugger, set break points and debug this code on your own.

Unless you give someone remote access to your PC to look at it, and are able to find someone who wants to do that. Your going to get same answers as last time...and till the end of time for that matter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900