Announcement

Collapse
No announcement yet.

An Old Onscreen Display Tip Revisited

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

  • An Old Onscreen Display Tip Revisited

    VERY SPECIAL UPDATE ADDED June 8, 2003

    Greetings --

    A few years ago, a PowerBASIC member named Dave Navarro posted a screen display shortcut - a function he called AT. I call it AT0 because the 2-letter AT is supposedly reserved in PB-DOS.

    Code:
    FUNCTION AT0 (BYVAL row AS LONG, BYVAL col AS LONG) AS STRING
      LOCATE row, col, 0:' cursor invisible
    END FUNCTION
    The function changes this ...
    Locate 12,10: Print "Dave"

    To This ...
    Print AT0(12,10);"Dave"

    Adapting Dave's Method, I came up with one that employs the STRING$ statement ...
    Code:
    FUNCTION QVC (BYVAL Gnum AS LONG, BYVAL Gchr AS LONG) AS STRING
      ? String$(Gnum, Gchr);
    ' print a given string character (Gchr) a specified number (Gnum) of times
    END FUNCTION
    Here's an example of AT0 and QVC together..
    Print AT0(11,1);QVC(22,95)
    __________________________________________________________________
    VERY SPECIAL UPDATE: 6-08-2003

    I've learned that the QVC shortcut function has a negative impact on program performance. You're better off just using PowerBASIC's built-in STRING$ function instead.

    Thanx-A-Lot, Frank -- My PB


    [This message has been edited by Frank Ferrell (edited June 21, 2003).]

  • #2
    The AT0() function is a useful tip there Frank! I also have a pair of similar functions that 'wrap' the COLOR and LOCATE statements so they can be used within a PRINT statement, much as you show above.

    Unfortunately, the QVC$() function is of somewhat less value though, since it is a "thin" wrapper for the built-in STRING$ function which could be used directly. That is, when implemented as the QVC() Function above, every time you use QVC(), it adds more code (overhead) to the compiled app (which pushes the parameters onto the stack, makes the function call, and then clean up the stack after the call returns). By using STRING$() directly, you eliminate the function call overhead with the same end result.

    The advantage of wrapping LOCATE and COLOR are much easier to define: those are statements (rather than functions), so wrapping them in a [string] function makes them somewhat more flexible for common use.



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Greetings --

      Thanks for your reply, Lance.

      I never realized that using QVC would have a negative impact on program performance - YEEKS! What a revelation that one is!

      Guess I'll retire Ol' QVC and use STRING$ instead.

      Thanx-A-Lot, Frank -- My PB


      [This message has been edited by Frank Ferrell (edited June 21, 2003).]

      Comment


      • #4
        Frank,

        I just wanted to say "Thank You" for taking the time to post that
        tip. I now already have converted my applicable PB/DOS programs
        to use it. I have also created a function based on the same principle
        for the COLOR statement. I am now working on doing the same for my
        PB/CC programs.

        Thanks! <IMG SRC="http://www.powerbasic.com/support/forums/smile.gif" ALT="smile">


        ------------------

        Comment


        • #5
          Greetings --

          Thank you, Clay. That's quite kind.

          Please feel free to share your code here. I'd certainly like to see it.

          Thanx-A-Lot, Frank -- My PB


          [This message has been edited by Frank Ferrell (edited June 21, 2003).]

          Comment


          • #6
            Greetings --

            This is for Lance or anyone else who may know the answer to the question I'm about to ask.

            I've just thought of another way FUNCTION QVC could be done. My question is - what impact on program performance would the code shown below have?

            Code:
             FUNCTION QVC (BYVAL Gnum AS LONG, BYVAL Gchr AS LONG, BYVAL Gprn AS LONG) AS STRING
               Chekkit=0
               IF Gnum>=1 THEN Chekkit=2
               IF Gchr>255 THEN Chekkit=1
               IF Gchr>=32 THEN Chekkit=Chekkit+2
            
               IF Chekkit=4 THEN
                  FOR Kount=1 to Gnum
                      PRINT CHR$(Gchr);
                  NEXT Kount
              ' a given character (Gchr) is printed a given number (Gnum) of times
                  IF Gprn=1 THEN PRINT:' only if no more text is printed on the same line
            
               ELSEIF Chekkit<>4 THEN
                 Color 15: PRINT "QVC received invalid data"
               END IF
             END FUNCTION
            Thanx-A-Lot, Frank -- My PB


            [This message has been edited by Frank Ferrell (edited June 21, 2003).]

            Comment


            • #7
              Greetings --

              Hmmm.

              Forgot about posting this. Still waiting on a reply to the last post I see.

              Thanx-A-Lot and Happy Holidays,
              Frank

              Comment


              • #8
                Frank,
                what impact on program performance would the code shown below have?
                I think it would have the same impact Lance mentioned, that is the function call overhead as opposed to calling a built-in function; plus, the time taken by the function to be executed, which i'm unable to figure out well.
                However it seems me that the job done by your 2nd QVC version can't be completely replaced by any built-in function, so there is no real comparison and the doubt might become whether the bit of extra work done by your function is worth the overhead; i think it depends on the kind of application.

                It is also possible that instead of calling CHR$(Gchr) Gnum times with the same Gchr, it would be faster putting CHR$(Gchr) into a string var before entering the loop, then referencing that var within the loop instead of CHR$(Gchr). This certainly wouldn't be true for Gnum = 1, but from 2 up, the higher is Gnum the better the speed gain should be.

                ------------------
                Davide Vecchi
                [email protected]

                [This message has been edited by Davide Vecchi (edited December 10, 2003).]

                Comment


                • #9
                  Greetings Davide --

                  Thanks for the info.

                  RE Putting Chr$(Gnum) outside a loop.

                  Just so that I understand you correctly, could you show me some demo code.

                  Thanx-A-Lot, Frank

                  Comment


                  • #10
                    Frank,

                    this is what i mean:
                    Code:
                    ...
                       IF Chekkit=4 THEN
                          
                          Char$ = CHR$(Gchr)
                    
                          FOR Kount=1 to Gnum
                    
                              PRINT Char$;
                    
                          NEXT Kount
                    
                          ...
                    ------------------
                    Davide Vecchi
                    [email protected]

                    Comment

                    Working...
                    X