Recent

Author Topic: I need help on file creation! file name and such!  (Read 6326 times)

captian jaster

  • Guest
I need help on file creation! file name and such!
« on: February 24, 2010, 03:06:00 am »
Code: [Select]
BEGIN
  writeln('File Manager');
  writeln('Type the file type you are creating and press Enter');
  readln(Ftype);
  writeln('You may type in what you want in your file');
  writeln('When you are done Type in [save]File then press Enter');
  repeat
  readln(body);
  until(body = '[save]File');
  writeln('Please type your file name and press Enter');
  readln(Fname);
  writeln('Preparing...');
  assignfile(Ufile,'C:\Xhydriks\Console\,Fname,.,Ftype');
  if fileexists('C:\Xhydriks\Console\',Fname,'.',Ftype) then
  begin
  writeln('File already exists!');
  writeln('Type something else');
  readln(Fname);
  end
  Else
  begin
    writeln('Saving...');
    Rewrite(Ufile);
    writeln(body);
    closefile(Ufile);
    delay(1000);
    writeln('Save complete!');
    readln(command);
  end;
END;

i was really proud of myself when i wrote the code but i added options for the user to choose not only the file type but the file name!
When i try to compile it it says wrong perimeters or something like that.. I look at the assign and fileexists code and you will see were im trying to get at..

mmab

  • Jr. Member
  • **
  • Posts: 89
Re: I need help on file creation! file name and such!
« Reply #1 on: February 24, 2010, 03:08:24 am »
You'd better read it first
http://library.thinkquest.org/27297/

instead of posting every single item that comes to your mind.

Bart

  • Hero Member
  • *****
  • Posts: 5663
    • Bart en Mariska's Webstek
Re: I need help on file creation! file name and such!
« Reply #2 on: February 24, 2010, 01:32:36 pm »
Even if the code would compile, it certainly is not gonna do what you want.

Take a look at this:

Code: [Select]
  repeat
  readln(body);
  until(body = '[save]File');

Lets say the user types the following: (<Enter> means the user presses Enter)
This is a really cool program.<Enter>
And I got it for free!<Enter>
[save]File<Enter>

What dou you think the value of body now actually is?

Later on you do this:

Code: [Select]
    Rewrite(Ufile);
    writeln(body);
    closefile(Ufile);

You probably want it to write the value of body to the file UFile.
Instead it is always gonna write the string '[save]File' to the screen.

Code: [Select]
  if fileexists('C:\Xhydriks\Console\',Fname,'.',Ftype) then
  begin
    writeln('File already exists!');
    writeln('Type something else');
    readln(Fname);
  end

This piece of code does actually nothing relevant at all.
The user is aksed to re-type the name of the file, but nothing is done with that information. (not to mention the fact that if you would use this information, you did not check if the user enterd the same name again, or the name of some other already existing file).

Some C&C

  • You are a beginning programmer. That's not a problem here. Many of us (including me) started out like you, stumbling in the dark.
    However you seem to be trying to program a real text editor into your program. This is way to complicated a task for a beginner.
  • Do not pester the users with pointless delays
  • Try to read up on the basics of programming. How to control the flow of the program. How to structure the code. Data structures.
  • Try to make some kind of "flow-chart" of what the program actually is supposed to do (use plain old pen and paper for this). Break it down into individual tasks that need to be done. If you can draw it this way, you already have the main algorithm of the program, and it will be much easier to translate it into code.
  • Start with simple things, then gradually tackle some more complicated problems

We really do not mind helping the totally unexperienced starters, but we expect you to put in some effort as well.


Happy programming.

Bart

captian jaster

  • Guest
Re: I need help on file creation! file name and such!
« Reply #3 on: February 24, 2010, 09:54:00 pm »
Ok i did that wrong..
Ima go through my 4rth rewrite of the code >.<

 

TinyPortal © 2005-2018