OK i'm trying to make a program that saves the records in a file... this is what i got so far and isn't working.. Thanks in advance

Program AccManager;

uses crt;

Type
  T_Account= record
    User:string[16];
    Password:string[12];
    Rango:byte;
  END;
  Arc_acc= file of T_Account;
var
  Acc:T_Account;
  option:byte;
  l,m:integer;
  Acu:Arc_acc;
{**********Preparar o Crear Archivos*********}
Procedure Accounts(Cuenta:T_Account);
Begin
  {$I-}
    reset (Acu);
  {$I+}
  If (IOResult = 0) Then
  Begin
    reset(Acu); {*The file exist*}
    assign(acu,'..\Data\Accounts.Gp7');
    reset(Acu);
    write(Acu,Cuenta);
    close(acu);
  End
  Else
  Begin
    rewrite (Acu); {* the file doesn't exis *}
    rewrite(Acu);
    assign(Acu,'..\Data\Accounts.Gp7');
    reset(Acu);
    write(Acu,Cuenta);
    close(acu);
  End;
End;
{*********cleaning***************}
{Procedure cleaning(var Acc:T_Account);

Begin

      User:='';
      Password:='';
      Rango:=0;
End;}
{---------------------}
{*********Register Account************}
Procedure Registering(var Acc:T_Account);{Separar en procesos, uno para cada mierda}
Begin
  clrscr;
  writeln('Nombre de Usuario, hasta 16 caracteres');
  readln(Acc.User);
  clrscr;
  writeln('Password, Hasta 12 caracteres');
  readln(Acc.Password);
  clrscr;
  writeln('Ingrese rango, 1 para Administrador, 2 para Gerente o 3 para Empleado');
  readln(Acc.Rango);
  Accounts(Acc);
End;
{-----------Program--------}

Begin
  repeat
    clrscr;
    gotoxy(33,5);
    writeln('Account Manager');
    gotoxy(33,6);
    writeln('---------------');
    gotoxy(33,9);writeln('[1] register account');
    gotoxy(33,10);writeln('[2] "Next time"');
    gotoxy(33,11);writeln('[3] "Next time"');
    gotoxy(33,12);writeln('[4] "Next time"');
    gotoxy(33,13);writeln('[5] exit to windows');
    readln(option);
    case option of
     1:Registering(Acc);
    End;{case}
  Until option = 5;
End.

Recommended Answers

All 8 Replies

So. Whats not working? In what way does it not work?

Its not making any files...

sry about double post, it seems i cant edit the last one right now... But when i launch the program i get error code = 102... ah yeah i forgot to change some names there Acc = Cuentas =P, I did change it full and it compiled, but i dont know what error code = 120 means... maybe i assigned the file in a wrong way or something x.x

Im guessing

Procedure Accounts(Cuenta:T_Account);
Begin
  {$I-}
    reset (Acu);
  {$I+}
  If (IOResult = 0) Then
  Begin
    reset(Acu); {*The file exist*}
    assign(acu,'..\Data\Accounts.Gp7');
    reset(Acu);
    write(Acu,Cuenta);
    close(acu);
  End
  Else
  Begin
    rewrite (Acu); {* the file doesn't exis *}
    rewrite(Acu);
    assign(Acu,'..\Data\Accounts.Gp7');
    reset(Acu);
    write(Acu,Cuenta);
    close(acu);
  End;
End;

You do a reset on a file you havent assigned, and then test the io result, but in the second io result you dont assign the file.. so no file would be made.

Im really lost there x.x.

I tried changing the place of assigns. but i still get the error code = 102, and i know its because the file isn't assigned, but this is my first program with files and records x.x

Ok i fixed that thanks.

Now i want to know how to make it not overwrite the file =/. I tryed Append(Acu); in place of reset(Acu); but looks like its only for text files...

Procedure Accounts(Acc:T_Account);{con Overwrite}
Begin
  Assign(Acu,'Accounts.Gp7');
  {$I-}
    reset(Acu);
  {$I+}
  If (IOresult=0) Then
    Begin
      reset(Acu);
      write(Acu,Acc);
      close(Acu);
    End
  Else
    Begin
      Rewrite(Acu);
      write(Acu,Acc);
      close(Acu);
    End;
End;

Im not convinced your IOresult test is the right answer - because assign is always the same, perhaps you want to use a file exists function

it works now =P, Thanks for your time

Procedure Accounts(Acc:T_Account);
Var
  i:integer;
Begin
  Assign(Acu,'Accounts.Gp7');
  {$I-}
    reset(Acu);
  {$I+}
  If (IOresult=0) Then
    Begin
      reset(Acu);
      i:=filesize(Acu);
      seek(Acu,i+1);
      write(Acu,Acc);
      close(Acu);
    End
  Else
    Begin
      Rewrite(Acu);
      write(Acu,Acc);
      close(Acu);
    End;
End;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.