Announcement

Collapse
No announcement yet.

Will this work?

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

  • Jerry Fielden
    replied
    [QUOTE]You ought to check out #DIM ALL. No more bugs due to variable-name typos!

    Maybe I should.

    Anyway, I got on my can and beat on these keys for a while and
    sure enough, those Subs did work. I did a little bit of changing
    and shorten some of the variables and tweeked on it some.

    If you want to post it to the other forum, like you said, I
    wrote a short program showing it's uses and how to save it
    to a file and retrieve it again. I guess I should have done
    this to start with. Later, Jerry Fielden


    $INCLUDE "PATH\and the include file"

    DECLARE SUB TextPutz (R1&, C1&, R2&, _
    Area$(), TxClr$())

    DECLARE SUB TextGetz (R1&, C1&, R2&, C2&, _
    Area$(), TxClr$())

    FUNCTION WinMain(BYVAL hCurInstance AS LONG, _
    BYVAL hPrevInstance AS LONG, _
    lpszCmdLine AS ASCIIZ PTR, _
    BYVAL nCmdShow AS LONG) _
    EXPORT AS LONG


    DIM TxClr$(80) : DIM Area$(80)

    InitConsoleTools hCurInstance,0,0,0,0,0 'Initialize CT..

    FOR y& = 1 TO 2
    COLOR 14, 1
    PRINT CHR$(201, 205, 205, 205, 205, 205, 205, 205, 205, _
    205, 205, 205, 205, 205, 187)
    PRINT CHR$(186) + " Hello World " + CHR$(186)
    PRINT CHR$(186) + " hello world " + CHR$(186)
    COLOR 11, 4
    PRINT CHR$(186) + " hello world " + CHR$(186)
    PRINT CHR$(186) + " Hello World " + CHR$(186)
    PRINT CHR$(200, 205, 205, 205, 205, 205, 205, 205, 205, _
    205, 205, 205, 205, 205, 188)


    R1& = 1'............R1& is starting row number
    C1& = 1'............C1& is Starting column number
    R2& = 6'............R2& is Ending row number
    C2& = 15'...........C2& is Ending row number

    TextGetz R1&, C1&, R2&, C2&, Area$(),TxClr$()

    '------------------ Save it to a file ---------------------

    OPEN "AREA15-6.bny" FOR BINARY AS #1 'Save 11 col. 4 rows
    FOR x& = 1 TO 6
    PUT$ #1, Area$(x&)'....Save 1 line of area
    PUT$ #1, TxClr$(x&)'...Save color for that 1 line
    NEXT x&
    CLOSE #1

    RESET Area$()'........clear the Arrays
    RESET TxClr$()

    '------------------- Load it back --------------------

    OPEN "AREA15-6.bny" FOR BINARY AS #1
    FOR x& = 1 TO 6
    GET$ #1, 15, Area$(x&)'....Have to know how wide
    GET$ #1, 15, TxClr$(x&)'...the area is for the
    NEXT x&'...................count, which is 11,
    '..........................I put it in file name

    '--------------- Move it to the middle of the screen-
    R1& = 1'.............Keep the same starting row
    C1& = 34'............Change starting column
    r2& = 6'.............Keep the same ending row

    TextPutz R1&, C1&, R2&, Area$(), TxClr$()

    '----------------------Move it to the bottom---------

    R1& = 20'........Change starting row
    C1& = 34'........Keep the same starting column
    R2& = 25'........Change ending row

    TextPutz R1&, C1&, R2&, Area$(), TxClr$()

    '--------------------Get wild with it----------------
    C1& = 1
    FOR R1& = 1 TO 24 STEP 6
    r2& = r1& + 5
    TextPutz R1&, C1&, R2&, Area$(), TxClr$()
    C1& = C1& + 16
    NEXT R1&

    SLEEP 5000
    color 7, 0
    CLS
    ConsoleWindow %FullScreen
    NEXT y&

    END FUNCTION

    SUB TextGetz (R1&, C1&, R2&, C2&, Area$(), TxClr$())
    'MOUSE OFF
    RESET Area$()
    RESET TxClr$()'...........Clear from last time
    Wide& = C2& - C1& + 1'....Find the width
    Tall& = R2& - R1&'........Find how many rows
    FOR x& = 1 TO Tall& + 1
    Area$(x&) = ConsolePeek(0, R1&, C1&, Wide&)
    TxClr$(x&) = ConsolePeek(%COLORS, R1&, C1&, Wide&)
    INCR R1&
    NEXT x&
    'MOUSE ON
    END SUB

    SUB TextPutz (R1&, C1&, R2&, Area$(), TxClr$())
    'mouse off
    DECR R1& : Row& = R1&
    Tall& = R2& - R1&'......Get the nr of lines
    FOR x& = 0 TO Tall&
    ConsolePoke 0, Area$(x&), Row&, C1&
    ConsolePoke %COLORS, TxClr$(x&), Row&, C1&
    INCR row&
    NEXT x&
    'mouse on
    END SUB




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




    [This message has been edited by Jerry Fielden (edited March 04, 2000).]

    Leave a comment:


  • Eric Pearson
    replied
    > I get most of my errors from mispelled words.

    You ought to check out #DIM ALL. No more bugs due to variable-name typos!

    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>

    Leave a comment:


  • Jerry Fielden
    replied
    Thanks for the Reply ERIC.

    I had already figgered out that PowerBasic didn't have
    a choice with Poke and Peek. I'm glad to hear that you
    think that those Subs will work, I've enjoyed using the
    original ones for many years, they were much faster than
    that C version I used to use with QB4. I never did figger
    that one out. I'd be much interested in seeing how you
    could speed them up. Go ahead and post them, I don't
    mind.

    I did make a mistake, it should have been +1 instead of
    -1, If you notice on the original that I wrote years ago,
    that I have

    FOR X = 1 to AreaDepth% + 1

    I moved the + 1 up one line on the New Sub and hit
    the wrong key, It should have been

    AreaDepth& = Row2& - Row1& + 1 ........In the original
    that +1 was needed, It wouldn't work right without it.


    Your right on the INCR Row1&, I get most of my errors
    from mispelled words.

    Thanks,......Jerry Fielden



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

    Leave a comment:


  • Eric Pearson
    replied
    Jerry --

    > I bought PBCC 2.0 and found that Poke$ and Peek$
    > got their tailfeathers plucked, they don't fly right.

    Just to be clear, Microsoft purposely, perniciously, plucked POKE$ and PEEK$, not PowerBASIC. (Try saying that three times fast!) Under Windows, those functions are allowed to access any memory that is available to your program... The problem is, Microsoft made the "console screen buffer" memory unavailable. So ConsolePoke and ConsolePeek were born, to simulate screen-buffer-memory operations. The actual technique that is used is API-based, not PEEK/POKE based, but the results are the same.

    > Will this work?

    You're on the right track, and all of the problems can definitely be solved, but I see a couple of minor problems. I think you're a row short during the Restore process. When you do this...

    Code:
    AreaDepth& = Row2& - Row1& - 1
    For x& = 1 to AreaDepth&
    ...it appears that if you are restoring a one-row area, the loop will run from 1 TO 0, i.e. nothing will happen. Or when you wrote DECR Row& did you mean DECR Row1&?

    Anyway, ConsolePole and ConsolePeek can definitely be used to do what you want (save/restore a rectangular console screen area), so I wouldn't worry about starting the conversion. Unless, that is, unless speed is a major problem. I don't want to be accused of false claims... Because of Microsoft's purposeful, pernicious, (sorry)... and the limitations that are placed on console API functions, ConsolePoke and ConsolePeek will not be as fast as the original PEEK$/POKE$ method. But I've got an idea about how to make your functions faster...

    In the future, I'm sure that PowerBASIC will appreciate it if you post questions about Console Tools in the Third Party Forum. In fact I'll probably post the finished functions there, so everybody can use them, if that's ok. After this thread is a couple of day's old (and he's sure that you've seen this response) Lance will probably move it there.

    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited March 02, 2000).]

    Leave a comment:


  • Jerry Fielden
    started a topic Will this work?

    Will this work?

    Years ago, right after PB 3.0 came out, I wrote these
    two screen portion Subs to replace TextGet and TextPut
    which was written in Microsoft C by John Clark Craig.
    I used them in QuickBasic 4.0, In QuickBasic, you had
    use Subs like these to copy a portion of the screen and
    paste it back. When I bought PB 3.0 I saw that Peek$
    and POKE$ could do the same thing with the same amount
    of code. TextGetz and TextPutz came out of that effort.
    Anyway, I bought PBCC 2.0 and found that Poke$ and Peek$
    got their tailfeathers plucked, they don't fly right.

    I rewrote TextGetz and TextPutz and used Console Tool's
    POKE and PEEK. I would like to know if this new version
    would work before I try to change the code from a large
    program to PBCC. I think it will work, but I'm not all
    that great of a programmer, if you experts think it will
    work, I'll do the conversion.


    SUB TextGetz (Row1%, Column1%, Row2%, Column2%, _
    Portion$())

    MouseHideCursor
    DEF SEG = &HB800'.............. for color monitor
    ERASE Portions$'............... Clear out last run
    DECR Row1%
    AreaWidth% = (Column2% - Column1%) * 2
    StartPosition% = (Column1% * 2) + (Row1% * 160) - 2
    AreaDepth% = Row2% - Row1%
    FOR x = 1 TO AreaDepth%
    Portion$(x) = PEEK$(StartPosition%, AreaWidth%)
    INCR StartPosition%, 160
    NEXT x
    MouseShowCursor
    END SUB

    Sub TextPutz (Row1%, Column1%, Row2%, Portion$())
    MouseHideCursor
    DEF SEG = &HB800
    DECR Row1% : DECR Column1%
    StartPosition% = (Column1% * 2) + (Row1% * 160)
    AreaDepth% = Row2% - Row1%
    FOR x = 1 to AreaDepth%
    POKE$ StartPosition%, Portion$(x)
    INCR StartPosition%, 160
    NEXT X
    MouseShowCursor
    END SUB

    The top two Subs are my originals and works great.
    The bottom two are the ones I'm wondering about.

    SUB TextGetz (Row1&,Column1&,Row2&,Column2&,Portion$(),Colors$())
    MOUSE OFF
    RESET Portion$() : DIM Portion$()
    DECR Row1%
    AreaWidth& = (Column2& - Column1&)
    AreaDepth& = Row2& - Row1&
    FOR x& = 1 to AreaDepth&
    Portion$(x&)= ConsolePeek(0, Row&1, Column&1,AreaWidth&)
    Colors$(x&)= ConsolePeek(%colors, Row&1, Column&1, _
    AreaWidth&)
    INCR Row&
    NEXT x&
    MOUSE ON
    END SUB


    SUB TextPutz (Row1&,Column&,Row2&,Column2&,Portion$,Colors$)
    MOUSE OFF
    DECR Row& : DECR Column1&
    AreaDepth& = Row2& - Row1& - 1
    For x& = 1 to AreaDepth&
    ConsolePoke 0, Portion$, Row1&, Column1&
    ConsolePoke %colors, Colors$, Row1&, Column1&
    INCR Row1&
    Next x&
    MOUSE ON
    END SUB

    Did I have to DIM after that RESET

    Thanks, Jerry Fielden






    [This message has been edited by Jerry Fielden (edited March 04, 2000).]
Working...
X