Program sifrarnik;
        Uses sysutils;
        Type
            myrecord=Record
                num:integer;
                itemname:String[20];
                price:Integer;
            End;
        Var
            data:array[1..10] of myrecord;
            doc:file of myrecord;
            operatingnum:integer;//item number used for reading and writeing into base
            error1,choice1,i,j,n,a:integer;
        begin
        Repeat
                Begin
                WriteLn('1. Add items date':10);
                WriteLn('2. See items data':10);
                WriteLn('3. Close');
                Write('Chose: ':10);
                ReadLn(choice1);
                Case choice1 of
                1 :
                    Begin
                        Assign(doc,'myfile.dat');
                        rewrite(doc);
                        Write('How many items data do u want to enter ':10);
                        ReadLn(n);
                        For i:=1 To n Do
                            Begin
                                WriteLn('Enter items num: ':10);
                                ReadLn(operatingnum);
                                with data[operatingnum] do
                                    begin
                                        num:=operatingnum;
                                        Write('Enter Items name: ':10);
                                        ReadLn(itemname);
                                        write('Enter items price: ': 10);
                                        ReadLn(prodcena);
                                        ReadLn;
                                    End;
                                Write(doc,data[operatingnum]);
                            End;
                        Close(doc);
                        readln;
                    End;
                2 :
                    Begin
                        Assign(doc,'myfile.doc');
                        Write('How many items date do u want to see ':10);
                        ReadLn(n);
                        For i:=1 to n do
                            Begin
                                WriteLn('Enter items num:':10);
                                ReadLn(operatingnum);
                                Reset(doc);
                                While not (eof(doc)) do
                                    Begin
                                        Read(doc,data[operatingnum]);
                                        with data[operatingnum] do
                                            Begin
                                                write('Items number:':10);
                                                writeln(num);
                                                Write('Items name: ':10);
                                                writeln(itemname);
                                                Write('Price: ':10);
                                                WriteLn(price);
                                                ReadLn;
                                            end;
                                    End;
                                Close(doc);
                                readln;
                            End;
                    End;
                3 : Error1:=0

                Else
                    Begin
                        WriteLn('Incorrect choice');
                        WriteLn('program will start again');
                        Error1:=1;
                    End;
                        End;
                End;
            Until Error1=0;
            Readln;
        End.

I want to have data base with items number, name price and to then call item by number(num). I tryed a lot of things and code doesnt work. it breaks on write(doc,data[operatingname]) line. Original record variable had more data, is memory problem? Can someone help? Please dont mind if there is some mistake in code. I originaly wrote it on Serbian and then translated it to english so i maybe have not corrected some things.

it breaks

What exactly happens? Do you get error codes? Is smoke coming out of your computer? Etc.
Tell us please.

it crashes somewhere. I somehow menaged to write to file but when i try to read i got error code 217

i changed the code a bit so i will resend it

   Program sifrarnik;
        Uses sysutils;
        Type
            myrecord=Record
                num:integer;
                itemname:String[20];
                price:Integer;
            End;
        Var
            data:array[1..10] of myrecord;
            doc:file of myrecord;
            operatingnum:integer;//item number used for reading and writeing into base
            error1,choice1,i,j,n,a:integer;
        begin
        Repeat
                Begin
                WriteLn('1. Add items date':10);
                WriteLn('2. See items data':10);
                WriteLn('3. Close');
                Write('Chose: ':10);
                ReadLn(choice1);
                Case choice1 of
                1 :
                    Begin
                        Assign(doc,'myfile.dat');
                        rewrite(doc);
                        Write('How many items data do u want to enter ':10);
                        ReadLn(n);
                        For i:=1 To n Do
                            Begin
                                WriteLn('Enter items num: ':10);
                                ReadLn(operatingnum);
                                with data[operatingnum] do
                                    begin
                                        num:=operatingnum;
                                        Write('Enter Items name: ':10);
                                        ReadLn(itemname);
                                        write('Enter items price':10);
                                        ReadLn(price);
                                        ReadLn;
                                    End;
                                Write(doc,data[operatingnum]);
                            End;
                        Close(doc);
                        readln;
                    End;
                2 :
                    Begin
                        Assign(doc,'myfile.doc');
                        Write('How many items date do u want to see ':10);
                        ReadLn(n);
                        For i:=1 to n do
                            Begin
                                WriteLn('Enter items num:':10);
                                ReadLn(operatingnum);
                                Reset(doc);
                                While not (eof(doc)) do
                                    Begin
                                        Read(doc,data[operatingnum]);
                                        with data[operatingnum] do
                                            Begin
                                                write('Items number:':10);
                                                writeln(num);
                                                Write('Items name: ':10);
                                                writeln(itemname);
                                                Write('Price: ':10);
                                                WriteLn(price);
                                                ReadLn;
                                            end;
                                    End;
                                Close(doc);
                                readln;
                            End;
                    End;
                3 : Error1:=0
                Else
                    Begin
                        WriteLn('Incorrect choice');
                        WriteLn('program will start again');
                        Error1:=1;
                    End;
                        End;
                End;
            Until Error1=0;
            Readln;
        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.