Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

why do i have bug with [Can't open File]

Posted on 2000-02-29
5
Medium Priority
?
299 Views
Last Modified: 2010-04-16
Can you tell em where do i have bug?

Program donors_app;
Uses Crt;

Const
  db_stuff = 'c:\-r76\db_stuff.bin';           {faila atrash. vieta}
  Name_signs = 15;                             {varda garums simbolos}
  SurName_signs = 25;                          {SurVaarda garums simbolos}
  Vec_signs = 3;
  n = 100;                                     {ierakstu skaits (max) }

Type
 donors = record
   Name: string[Name_signs];                   {Vards 15 simb. gars}
   SurName: string[SurName_signs];             {SurVaards 25 simb. gars}
   RegNum: integer;                            {Reg. Numura garums 8 simb.}
   Vecums: String[Vec_signs];                  {Vecums 0 - 150}
   Dzimums: string[4];                            {dzimums - vir./siev.}
End;


FFile = file of donors;                 {faila tips}
rec = array[1..n] of donors;            {masivu tips, pec faila tipa glab.}

var fails: FFile;                       {failam dotais nosaukums}
    kop_rec: integer;                   {kopejo ierakstu skaits}


Function Pareizs_REC(i:integer):boolean;   {parbauda vai eksistee ieraksts}
var g: rec;                                {ierakstu skaits}
    j:integer;                             {skaita ierakstus}
begin
 j:=1;                                     {ierkast nr. 1}
 Pareizs_Rec:= true;                       {ieraksts eksitee}
 {$I-}
 Close(fails); {}                          {aizver failu}
 {$I+}
 Assign(fails,db_stuff);                   {faila/lokacijas asigneshana}
 Reset(fails);                             {izdzeshana}
 While ((Eof(fails))<>true) do
   begin
     read(fails,g[j]);                     {nolasa no faila j-to iekatu}
     inc(j);                               {noapalo j, lai naf bugu}
   end;
 if i+1>j then Pareizs_REC:=false;         {parbauda vai eksiste nakamais ieraksts}
End;

Procedure MakeRec;                             {recordu veidoshana}
var g: rec;
    Y: char;   s,temp: string;   ok: boolean; a,i,b,rez:integer;
      TempSTR,chose: String;  Code,TempG: Integer;
      Label 12; Label 13;
Begin
{$I-}
Close(fails);{}
{$I+}
Assign(fails,db_stuff);
{Reset(fails);}
If IOResult <> 0 then Rewrite(fails); {}
Seek(fails,FileSize(fails));                    {meklee faila beigas}
inc(kop_rec);
ClrScr;
Writeln('Pec neprecizas vertibu ievadishanas, tas bus jaaievada atkartoti!');
GotoXY(3,22);
Write('-press enter-'); Readln;
ClrScr;
Writeln('Ievadiet personas vardu - ',Name_signs,' simboliem');
GotoXY(3,22);
Write('-ievadiet- ');
ReadLn(g[kop_rec].Name);           {ieglabaa masivaa name}
ClrScr;
Writeln('Ievadiet personas uzvardu - ',SurName_signs,' simboliem');
GotoXY(3,22);
Write('-ievadiet- ');
ReadLn(g[kop_rec].SurName);                        {ieglabaa masivaa SurName}

ClrScr;                                            {izveido reg numuru}
Writeln('reg-num tiks noteikts automatiski');
GotoXY(3,22);
Write('-press enter-');
ReadLn;
 Randomize;
    rez := Random(9999);
    if rez<=1000 then rez:=rez+1000;
 ClrScr;
    Write('Jusu registracijas numurs--> ', rez);
    GotoXY(3,22); Write('-press enter-');
    g[kop_rec].RegNum := rez;
readln;

ok:=false;
While ok <> true do                      {ievadam datus -vecums}
begin
13: ClrScr;
    Writeln('Ievadiet personas vecumu: ');
    GotoXY(3,22); Write('-ievadiet- ');
    ReadLn(temp);
      begin
       a:=0;
        for i:=1 to length(temp) do begin
         if (ord(temp[i])>=48) and (ord(temp[i])<=57)
          then b:=1  {ASCII kodaa sk}
        else a:=a+1;
     if a>=1 then goto 13
       else ok:=true;
       g[kop_rec].vecums:=temp;
  end;
 end;
end;

Repeat                       {parbauda ievadisha par siev/vir}
   ClrScr;
    Writeln('Izvelas vajadzigo: [0-Siev/1-Vir]');
    GotoXY(3,22); Write('-ievadiet- ');
      ReadLn(TempSTR);
      Val(TempSTR,TempG,Code);
    Until ((Code = 0) And (TempG In [0..1]));
       if tempStr = '1' then chose:='vir.';
       if tempStr = '0' then chose:='siev.';
      g[kop_rec].Dzimums:=chose;
ClrScr;
Writeln('Saglabat datus failaa?  [Y/N]');
GotoXY(3,22); Write('-izvele- ');
readln(Y);
if (Y = 'Y') or (Y = 'y') then write(fails,g[kop_rec]);
End;

Procedure PrintRec;
var g: rec;
i,j: integer;
Begin
ClrScr;
{$I-}
Close(fails);{}
{$I+}
Assign(fails,db_stuff);
Reset(fails);{}
i:=1; j:=0;
While ((Eof(fails))<>true) do
 begin
   inc(j);
   Read(fails,g[i]); {}
   Writeln('nr:             ',i);
   Writeln('name:           ', g[i].name);
   Writeln('surname:        ', g[i].surname);
   Writeln('reg nr:         ', g[i].regnum);
   Writeln('vecums:         ', g[i].vecums);
   Writeln('dzimums:        ', g[i].dzimums);
   writeln;
 end;
readln;
End;


begin
MakeRec;
PrintRec;
end.


0
Comment
Question by:fr0x
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Hypo
ID: 2569752
I can run your code without any errors. My guess is either that the file c:\-r76\db_stuff.bin doesn't exist or that you don't have access to write to the disk. e.g. if you're on a network, you might not have access to write files on C:

other than that, I don't know why your code throws an error at you!
0
 

Author Comment

by:fr0x
ID: 2569917
Hmz.. I forget to told, taht i have bug with ..!!

I can add data and print data on screen! but when i start this process again.. to add new data to file *.bin!

all data is been erased and i can save just the last data entry!

why?

i had to get such a result:
Number 1.
Name sjkhdj
surname lkss
....

Number 2
Name jdewh
Surname kjxhid
....

Number 3
Name jdesdesd
Surname kjsdfsfe
....

etc.

Can you tell me where is a problem?
0
 
LVL 3

Accepted Solution

by:
sumant032199 earned 150 total points
ID: 2569942
hello fr0x,
There can be following reasons

1. File does not exist.
2. PAth does not exist.
3. Drive does not exist.
4. File readonly.
5. Shared file under multiuser / multitasking system.
0
 

Author Comment

by:fr0x
ID: 2570009
I have this error:
1. File does not exist.

cn you tell how to solve this?
0
 
LVL 12

Expert Comment

by:Hypo
ID: 2570611
Ok, I've made a few changes to your code... At two points you started the procedures (Make_Rec and Print_Rec) by closing a file (fails), I moved those line to the end of the procedures instead. And I think it works fine now!
(I would have posted this as an answer if I it were'nt already locked!)


Take a look at it, Does it work like you wanted it to do?

Program donors_app;
Uses Crt;

Const
  db_stuff = 'e:\program\pascal\test2.pas';           {faila atrash. vieta}
  Name_signs = 15;                             {varda garums simbolos}
  SurName_signs = 25;                          {SurVaarda garums simbolos}
  Vec_signs = 3;
  n = 100;                                     {ierakstu skaits (max) }

Type
 donors = record
   Name: string[Name_signs];                   {Vards 15 simb. gars}
   SurName: string[SurName_signs];             {SurVaards 25 simb. gars}
   RegNum: integer;                            {Reg. Numura garums 8 simb.}
   Vecums: String[Vec_signs];                  {Vecums 0 - 150}
   Dzimums: string[4];                            {dzimums - vir./siev.}
End;


FFile = file of donors;                 {faila tips}
rec = array[1..n] of donors;            {masivu tips, pec faila tipa glab.}

var fails: FFile;                       {failam dotais nosaukums}
    kop_rec: integer;                   {kopejo ierakstu skaits}


Function Pareizs_REC(i:integer):boolean;   {parbauda vai eksistee ieraksts}
var g: rec;                                {ierakstu skaits}
    j:integer;                             {skaita ierakstus}
begin
 j:=1;                                     {ierkast nr. 1}
 Pareizs_Rec:= true;                       {ieraksts eksitee}
 {$I-}
 Close(fails); {}                          {aizver failu}
 {$I+}
 Assign(fails,db_stuff);                   {faila/lokacijas asigneshana}
 Reset(fails);                             {izdzeshana}
 While ((Eof(fails))<>true) do
   begin
     read(fails,g[j]);                     {nolasa no faila j-to iekatu}
     inc(j);                               {noapalo j, lai naf bugu}
   end;
 if i+1>j then Pareizs_REC:=false;         {parbauda vai eksiste nakamais ieraksts}
End;

Procedure MakeRec;                             {recordu veidoshana}
var g: rec;
    Y: char;   s,temp: string;   ok: boolean; a,i,b,rez:integer;
      TempSTR,chose: String;  Code,TempG: Integer;
      Label 12; Label 13;
Begin
{$I-}
Assign(fails,db_stuff);
Reset(fails);
If IOResult <> 0 then Rewrite(fails); {}
Seek(fails,FileSize(fails));                    {meklee faila beigas}
inc(kop_rec);
ClrScr;
Writeln('Pec neprecizas vertibu ievadishanas, tas bus jaaievada atkartoti!');
GotoXY(3,22);
Write('-press enter-'); Readln;
ClrScr;
Writeln('Ievadiet personas vardu - ',Name_signs,' simboliem');
GotoXY(3,22);
Write('-ievadiet- ');
ReadLn(g[kop_rec].Name);           {ieglabaa masivaa name}
ClrScr;
Writeln('Ievadiet personas uzvardu - ',SurName_signs,' simboliem');
GotoXY(3,22);
Write('-ievadiet- ');
ReadLn(g[kop_rec].SurName);                        {ieglabaa masivaa SurName}

ClrScr;                                            {izveido reg numuru}
Writeln('reg-num tiks noteikts automatiski');
GotoXY(3,22);
Write('-press enter-');
ReadLn;
 Randomize;
    rez := Random(9999);
    if rez<=1000 then rez:=rez+1000;
 ClrScr;
    Write('Jusu registracijas numurs--> ', rez);
    GotoXY(3,22); Write('-press enter-');
    g[kop_rec].RegNum := rez;
readln;

ok:=false;
While ok <> true do                      {ievadam datus -vecums}
begin
13: ClrScr;
    Writeln('Ievadiet personas vecumu: ');
    GotoXY(3,22); Write('-ievadiet- ');
    ReadLn(temp);
      begin
       a:=0;
        for i:=1 to length(temp) do begin
         if (ord(temp[i])>=48) and (ord(temp[i])<=57)
          then b:=1  {ASCII kodaa sk}
        else a:=a+1;
     if a>=1 then goto 13
       else ok:=true;
       g[kop_rec].vecums:=temp;
  end;
 end;
end;

Repeat                       {parbauda ievadisha par siev/vir}
   ClrScr;
    Writeln('Izvelas vajadzigo: [0-Siev/1-Vir]');
    GotoXY(3,22); Write('-ievadiet- ');
      ReadLn(TempSTR);
      Val(TempSTR,TempG,Code);
    Until ((Code = 0) And (TempG In [0..1]));
       if tempStr = '1' then chose:='vir.';
       if tempStr = '0' then chose:='siev.';
      g[kop_rec].Dzimums:=chose;
ClrScr;
Writeln('Saglabat datus failaa?  [Y/N]');
GotoXY(3,22); Write('-izvele- ');
readln(Y);
if (Y = 'Y') or (Y = 'y') then write(fails,g[kop_rec]);
close(fails);
{$I+}
End;

Procedure PrintRec;
var g: rec;
i,j: integer;
Begin
ClrScr;
{$I-}
Assign(fails,db_stuff);
Reset(fails);{}
i:=1; j:=0;
While ((Eof(fails))<>true) do
 begin
   inc(j);
   Read(fails,g[i]); {}
   Writeln('nr:             ',i);
   Writeln('name:           ', g[i].name);
   Writeln('surname:        ', g[i].surname);
   Writeln('reg nr:         ', g[i].regnum);
   Writeln('vecums:         ', g[i].vecums);
   Writeln('dzimums:        ', g[i].dzimums);
   writeln;
 end;
readln;
Close(fails);{}
{$I+}
End;


begin
MakeRec;
PrintRec;
end.

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question