Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

A reasonably accurate time delay...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A reasonably accurate time delay...

    Code:
    '   PB/DOS has a built-in Delay function. I find this to be an extrodinairly
    '   useful tool. PB/CC does not. I find this to be a major pain in the *ss,
    '   so.......
    '
    '   It seems as if this sub will digest fractional number just fine, i.e.,
    '   Delay(1.5) seems to be working just as well as Delay(5).
    '
    '   This function (sub) may not be as accurate as a micro-timer but for my
    '   purposes, it works just fine.
                                                        '
    DECLARE SUB Delay(DelayTime AS SINGLE)              '<***** Needed
    DECLARE SUB cowboy                                  ' Show something.
                                                        '
        GLOBAL wheel AS LONG                            '
        GLOBAL pin   AS LONG                            '
        GLOBAL pcol  AS LONG                            '
                                                        '
                                                        '
        FUNCTION PBMAIN()                               '
        DIM DelayTime AS SINGLE                         ' <***** Needed
        DIM dStep AS SINGLE                             '
                                                        '
        DelayTime = .025                                ' Initial delay set.
        dStep = .005                                    ' Keyboard speed step
                                                        '
        LOCAL x AS LONG                                 '
        COLOR 14,1                                      '
        CLS                                             '
        DO                                              '<-:
        LOCATE 1,1 : PRINT;DelayTime;SPACE$(10);        '  |
                                                        '  |
        Delay(DelayTime)                                '  |<***** Needed
                                                        '  |
        cowboy                                          '  |A little show-off
        an$ = INKEY$                                    '  |
        IF an$= CHR$(27) THEN EXIT LOOP                 '  |
        IF an$= "+" OR an$= "=" THEN                    '<:| Press "+" or "=" to
        DelayTime = DelayTime + dStep                   ' &#0124; &#0124; slow things down.
        END IF                                          '<:| (Increase the delay time)
                                                        '  |
        IF an$= "-" OR an$= "_" THEN                    '<:| Press "_" or "-" to
        DelayTime = DelayTime - dStep                   ' &#0124; &#0124; speed things up.
        END IF                                          '<:| (Decrease the delay time)
                                                        '  |
        IF DelayTime < dStep THEN DelayTime = 0         '  |
        LOOP                                            '<-:
        END FUNCTION                                    '
                                                        '
    REM *********************************************** '
    REM * And here she be. All that needs to be added * '
    REM * is the delay value somewhere else.          * '
    REM *********************************************** '
                                                        '
    SUB Delay(DelayTime AS SINGLE)                      '
        LOCAL StartTime  AS DOUBLE                      '
        LOCAL EndTime    AS DOUBLE                      '   Time to finish
                                                        '
        StartTime = TIMER                               '
        EndTime = StartTime + DelayTime                 '   Add the delay.
                                                        '
        IF EndTime > 86400 THEN                         '<: Wrap-Around
        EndTime = EndTime - 86400                       ' | at midnight.
        END IF                                          '<:
                                                        '
        DO UNTIL StartTime => EndTime                   '   Keep looping until.....
        StartTime = TIMER                               '
        SLEEP 0                                         '
        LOOP                                            '
        END SUB                                         '
                                                        '
    SUB Cowboy                                          '
        IF pcol < 3 THEN pcol = 3                       '
        wheel = 3                                       '
                                                        '
        LOCATE  9,pcol-2 : PRINT;SPACE$(6);             '
        LOCATE 10,pcol-2 : PRINT;SPACE$(6);             '
        LOCATE 11,pcol-2 : PRINT;SPACE$(6);             '
        LOCATE 12,pcol-2 : PRINT;SPACE$(6);             '
        pcol = pcol + 1                                 '
        IF pcol = 78 THEN pcol = 3                      '
                                                        '
        LOCATE 10,pcol     : PRINT;"o  O";              '
        LOCATE 11,pcol - 2 : PRINT;"\_|_/";             '
        LOCATE 12,pcol - 2 : PRINT;"/   \";             '
        LOCATE 12,pcol - 2                              '
        pin = pin + 1                                   '
        IF pin = 5 THEN pin = 1                         '
        IF pin = 1 THEN PRINT;"/  \-";                  '
        IF pin = 2 THEN PRINT;"-  \\";                  '
        IF pin = 3 THEN PRINT;"\  \|";                  '
        IF pin = 4 THEN PRINT;"|  \/";                  '
                                                        '
        END SUB                                         '
    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

  • #2
    Did you try the SLEEP command?

    ------------------
    Scott Turchin
    MCSE, MCP+I
    Computer Creations Software
    ----------------------
    Sometimes you give the world the best you got, and you get kicked in the teeth.
    Give the world the best you got anyway.
    - Ted Nugent (God, Guns, and Rock n' Roll)
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      http://www.powerbasic.com/support/pb...ad.php?t=30715

      any more questions/coments should go to another forum.


      ------------------
      There are no atheists in a fox hole or the morning of a math test.
      If my flag offends you, I'll help you pack.

      Comment

      Working...
      X