Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
setting a speed in Pascal Posted by siriss on 22 Jan 2013 at 12:09 PM
Hi, all.
I'd like to know how I can set the speed of the steps followed by a program in Pascal. I'm doing a program that deletes the letters of a sentence, from the end of that sentence to the beggining, and it has to be one letter per second.

waiting for suggestions,

siriss.
Report
Re: setting a speed in Pascal Posted by Actor21 on 22 Jan 2013 at 8:25 PM
The CRT unit has a procedure called delay.
program howto ;

uses crt ;

begin
    delay(1000)
end

The argument of delay is the length of the delay in milliseconds. delay(1000) pauses the program for one second. Depending on how accurate your delay has to be you might want to use delay(950) or some other number less than 1000. Experiment.
Report
Re: setting a speed in Pascal Posted by siriss on 22 Jan 2013 at 11:30 PM
Well, stil not working..

Program del_sentence;
var s: string;
i: byte;
uses crt;
begin
clrscr;
writeln('sentence is deleting itself');
readln(s);
for i:=length(s) downto 2 do begin
s[i]:=' ';
delay(1000);
end;
end.

What .. did I miss? Everything seemed fine to me.,
Thanks again.
Report
Re: setting a speed in Pascal Posted by siriss on 22 Jan 2013 at 11:39 PM
Well, stil not working..

Program del_sentence;
var s: string;
i: byte;
uses crt;
begin
clrscr;
writeln('sentence is deleting itself');
readln(s);
for i:=length(s) downto 2 do begin
s[i]:=' ';
delay(1000);
end;
end.

What .. did I miss? Everything seemed fine to me.,
Thanks again.
Report
Re: setting a speed in Pascal Posted by siriss on 22 Jan 2013 at 11:42 PM
Well, stil not working..

Program del_sentence;
var s: string;
i: byte;
uses crt;
begin
clrscr;
writeln('sentence is deleting itself');
readln(s);
for i:=length(s) downto 2 do begin
s[i]:=' ';
delay(1000);
end;
end.

What .. did I miss? Everything seemed fine to me.,
Thanks again.
Report
Re: setting a speed in Pascal Posted by Actor21 on 24 Jan 2013 at 2:29 AM
program del_sentence ;

uses crt ;   { 'uses' must be first statement after 'program'  }

var
   s : string ;
   i : byte ;

begin
   clrscr ;
   write ('Enter a sentence. ') ;
   readln(s) ;
   writeln('sentence is deleting itself') ;

   while length(s) > 0 do begin
      writeln(s) ;
      delete(s,length(s),1) ;   { use 'delete' - not s[1] = '' }
      delay (1000)              { 'delay' does not seem to work on my machine
                                  I had to use 15000 for a one second delay
                                  experiment }
   end
end.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.