×
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

10,000 EMPLOYEES

10,000 EMPLOYEES

10,000 EMPLOYEES

(OP)
HI,
i'm trying to figure out the best way to create 9999 random employees each with an employee number (0001-9999) attached to them. i think that for the purpose of what i need, it would be easier to create them with all the same name followed by their number. ie. JOHN SMITH0001,JOHN SMITH0002 etc...
any ideas for a new pascal user.
cheers

RE: 10,000 EMPLOYEES

Use the function random:
random(x) generates a random number in the interval [0,1,...x[ (i.e. x not included).

Use the function str to convert a number to a string:
str(125,s); => s = '125'

Use + to concatenate strings:
s:='john'+'125'; => s = 'john125'

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.

RE: 10,000 EMPLOYEES

(OP)
THANX Bertv100,
when i said i was a new pascal user, i meant really new. so i dont really understand any of what you just said except for your signature (cool by the way) i'll look in some books to try and figure out what you're telling me.
regards
chriscarlile911
p.s. if, "once you pop, you can't stop", why do pringle come in a resealable tub!?!?!?

RE: 10,000 EMPLOYEES

Some example code:

FUNCTION generate_name(name : string; number : word) : string;
VAR number_string : string;
begin
  { convert the given number to a string: }
  str(number,number_string);
  { push zeroes in front of it, so all "numbers" have the same length }
  while length(number_string)<4 do
   number_string:='0'+number_string;
  { return as result the concatenation of the given name and the number }
  generate_name:=name+number_string;
end;


Executing generate_name('JOHN SMITH',1); will result in the value 'JOHN SMITH0001'.
The following example will print this result on screen:
VAR s : string;
BEGIN
  s:=generate_name('JOHN SMITH',1);
  writeln(s);
END.


If you don't understand all this code, you should really read some book on Pascal. People in this forum can only help if you already know Pascal's syntax and are at least remotely familiar with its iteration and selection techniques.

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.

RE: 10,000 EMPLOYEES

Bertv100, can't you get str to produce the right format automatically by specifying it with ':' things, like you can in writeln?? I can't remember....

RE: 10,000 EMPLOYEES

Yes you can, but I took Chris' requirement which was: zeroes in front of number. The ':' formatting uses spaces.

Also, since he's a beginning programmer, an example of a while loop can be more helpful in learning to work in Pascal than a cryptic ':' construct.

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
http://student.vub.ac.be/~bvingerh/
Don't worry what people think about you. They're too busy wondering what you think about them.

RE: 10,000 EMPLOYEES

true, true!
The ':' thing isn't very well documented in help-files, either.

RE: 10,000 EMPLOYEES

I have taught and designed random files with random record processing, if that is really what you want, for about 40 years and designing & programming a good random file processing system with a good packing factor, synonyms spreading, overflows, dynamic key reuse and appox., 1.2 reads per request, chains, skip techniques & prime divide is not something for the faint of heart. I have taught a one week design & coding overview class to experienced people and sometimes they have trouble understanding the issues.

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