setting a speed in Pascal - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

setting a speed in Pascal

sirisssiriss Posts: 4Member
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.

Comments

  • Actor21Actor21 Posts: 35Member
    The CRT unit has a procedure called [b]delay[/b].
    [code]
    program howto ;

    uses crt ;

    begin
    delay(1000)
    end
    [/code]
    The argument of [b]delay[/b] is the length of the delay in milliseconds. [b]delay(1000)[/b] pauses the program for one second. Depending on how accurate your delay has to be you might want to use [b]delay(950)[/b] or some other number less than 1000. Experiment.
  • sirisssiriss Posts: 4Member
    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.
  • sirisssiriss Posts: 4Member
    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.
  • sirisssiriss Posts: 4Member
    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.
  • Actor21Actor21 Posts: 35Member
    [code]
    program del_sentence ;

    uses crt ; {[red] 'uses' must be first statement after 'program' [/red] }

    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) ; {[red] use 'delete' - not s[1] = '' [/red]}
    delay (1000) {[red] 'delay' does not seem to work on my machine
    I had to use 15000 for a one second delay
    experiment [/red]}
    end
    end.
    [/code]
Sign In or Register to comment.