×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Saving and reading data files

Saving and reading data files

Saving and reading data files

(OP)
OK im no novice with this aspect but for some odd reason, my read procedure isnt doing its job and its rather annoying!

PROCEDURE save_password(user,pword:string; value:longint);

VAR
  pin : pword_rec;
  pfl : pword_file;

BEGIN
  pin.user := user;
  pin.pass := pword;
  pin.value := value;
  assign(pfl,passfile); {constant = 'C:\Data.dat'}
  reset(pfl);
  seek(pfl,filesize(pfl));
  write(pfl,pin);
  close(pfl);
END;

That, Im glad to say, works fine. The fact the file size increases is testament to that.
I also have a search procedure that correctly reads the file and does what its meant to with retrieved data...

This however, doesnt work:

PROCEDURE display_users;

VAR
  pin : pword_rec;
  pfl : pword_file;
  y   : integer;
  s   : string;

BEGIN
  y := 3;
  frame(1,1,80,50);
  assign(pfl,userfile);
  reset(pfl);
  WHILE NOT EOF(pfl) DO
    BEGIN
      read(pfl,pin);
      writexy(2,y,pin.user);
      y := y + 1;
      str(filezise(pfl),s);
      writexy(3,2,s);
    END;
END;

S is somehow 1 and no user names are displayed on screen. Im only using the str and filesize to check it works. I know for a fact that there are more than 50 users saved in the file ( i did a repeat loop, adding in users to test another aspect of the program).

This is really puzzling. Can any one explani what's going on please?

TIA

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

RE: Saving and reading data files

(OP)
pword_rec = RECORD
  user,pass : string;
  value     : longint;
END;

pword_file = FILE OF pword_rec;

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

RE: Saving and reading data files

(1) How much does the size of your file increase when you add a single new user.
It should increase exactly 516 bytes (2 standard strings and a longint), and if it isn't exactly that value, you have a problem.

(2) Do you mean filezise or filesize in this example?
If you really typed filezise in the str(    ) statement, and did something similar somewhere else, it's possible you've defined a type filezise and typecast pfl as one of those, and thus made a mess of the str statment???? unlikely, but....

(3) If you have a search procedure that reads data and interprets it correctly, then the problem MUST be in the procedure that's supposed to print filesize and doesn't. Go back and look at the procedure that Does work, and see how it differs...

RE: Saving and reading data files

(OP)
filesize*

It takes 2 users to raise it 1Kb so yeah I assume its 516b

Ive checked, they're almost identical, except for the search procedure has the IF x = y THEN statement and the read procedure doesnt.

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

RE: Saving and reading data files

Try specifying a fixed length for the string parts:


pword_rec = RECORD
  user,pass : string[64];
  value     : longint;
END;

RE: Saving and reading data files

     Are you sure it's the same file?  Note that you are using different names in the two routines!

RE: Saving and reading data files

Errors in other parts of the program can make strange behaviours, like a loop writing beyond an array size. Then one of the other variables may change randomly.

RE: Saving and reading data files

(OP)
omg ... i probablly had a good reason to add in the userfile constant but then i went to sleep and now ... well its irrelevant and as a result no longer resides in the program ;)

Thanks for pointing out im an idiot ^^;

Sorry for the huge delay, ive been busy recently and Ive just had to format my C:\ so there's been a few problems with s/w installation and such.

Any who THANKS!

~*Gwar3k1*~
"To the pressure, everything's just like: an illusion. I'll be losing you before long..."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close