Announcement

Collapse
No announcement yet.

GET statement parameters

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

  • GET statement parameters

    I'd like to use the GET statement with something other than an
    explicit array for its destination buffer. What would be nice
    is to be able to define a TYPE such as:

    TYPE ScreenBlockRec
    Hsize as INTEGER
    Vsize as INTEGER
    DAT(143) as INTEGER
    END TYPE

    But it seems that the GET statement does not permit anything
    other than explicit arrays as an argument. It also doesn't
    seem to permit pointers to arrays, UNIONs, or structure
    element references. Has anyone wrestled with this bear before?

    --Greg

  • #2
    What version of PowerBASIC are you using? The following code works fine in PB/DOS 3.5:
    Code:
    TYPE MyType
      a AS STRING * 20
      b AS STRING * 20
    END TYPE
     
    DIM g AS MyType
     
    OPEN "GET.BAS" FOR RANDOM AS #1 LEN = 40
     
      GET 1, 1, g
      PRINT g.a
      PRINT g.b
     
      GET 1, 2, g
      PRINT g.a
      PRINT g.b
     
    CLOSE
    --Dave

    ------------------
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Home of the BASIC Gurus
    www.basicguru.com

    Comment


    • #3
      Originally posted by Dave Navarro:
      What version of PowerBASIC are you using? The following code works fine in PB/DOS 3.5:
      <font face="Courier New, Courier" size="3"><pre>
      TYPE MyType
      a AS STRING * 20
      b AS STRING * 20
      END TYPE

      DIM g AS MyType

      OPEN "GET.BAS" FOR RANDOM AS #1 LEN = 40

      GET 1, 1, g
      PRINT g.a
      PRINT g.b

      GET 1, 2, g
      PRINT g.a
      PRINT g.b

      CLOSE
      </pre></font>
      --Dave
      Ah. I see that I should have been a tad more specific. The
      "GET" statement I had in mind was the one for reading the
      screen, as in:

      GET (1,1) - (10,10),Buffer%

      Sorry about the confusion.


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

      Comment


      • #4
        You can only specify a numeric array with the graphical GET statement. However, there is a solution: pointers.

        Lets say you want to use GET and store/work on the data as a UDT (or a UDT array). First, we define our UDT block:
        Code:
        type mytype
          a as integer
          b as long
          c as string * 94
        end type
        Next, we create the compulsory numeric array to get our data from the graphics screen, and create a UDT pointer:
        Code:
        dim a%(1:1000)
        dim b as mytype ptr
        Next, we set the target address for the pointer to the base address of the numeric array:
        Code:
        b = varptr32(a%(1)) ' 32-bit address of a%()
        At this point, the pointer target (@b) is actually the data stored within the numeric array. In effect, we have created a union. Now lets play with the values and examine the results:
        Code:
        a%(1) = 999
        print a%(1),@b.a
        @b.a = 888
        print a%(1), @b.a
        This proves the 'union' effect: altering the data at @b.a affects the value stored in a%(1).

        Now if we want to treat the numeric data as an array of these UDT structures, we can introduce an even more powerful technique: Indexed Pointers. Lets see them in action:
        Code:
        a%(1) = 999
        print a%(1),@b[0].a
        @b[0].a = 888
        print a%(1), @b[0].a
        a%(2) = 999
        print a%(2),@b[1].a
        @b[1].a = 888
        print a%(2), @b[1].a
        This example shows how easily we can treat the data in the numeric array as an array of UDT structures. The square brackets are the UDT array subscript number, which is always zero-based.

        This makes life simple because you can chop and change between different UDT pointers so you can 'interpret' the data in completely different ways without moving the data around in memory at all! All that is necessary is to define your collection of UDT's and a pointer for each type.

        Hopefully this will give you food for thought! Pointers and Indexed Pointers are very powerful and can be used to solve all sorts of data manipulation problems. As a bonus, pointers are typically very fast at runtime - you can give data manipulation code a real boost by using pointers instead of more generic code (such as MID$() for strings, or POKE/PEEK, etc).

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

        Comment


        • #5
          Originally posted by Lance Edmonds:
          You can only specify a numeric array with the graphical GET statement. However, there is a solution: pointers.

          [ ... nice examples snipped...]

          This example shows how easily we can treat the data in the numeric array as an array of UDT structures. The square brackets are the UDT array subscript number, which is always zero-based.

          This makes life simple because you can chop and change between different UDT pointers so you can 'interpret' the data in completely different ways without moving the data around in memory at all! All that is necessary is to define your collection of UDT's and a pointer for each type.

          Hopefully this will give you food for thought! Pointers and Indexed Pointers are very powerful and can be used to solve all sorts of data manipulation problems. As a bonus, pointers are typically very fast at runtime - you can give data manipulation code a real boost by using pointers instead of more generic code (such as MID$() for strings, or POKE/PEEK, etc).
          Yes, I suppose that this will be an okay workaround for me. I need to create a table of small images that
          will be "plugged" into the screen at various places. These images will first be built with built-in
          graphics commands, then read out of the video memory and stored for later use. I guess I'll just allocate
          one whopping big array and index the heck out of it with the pointers/UDT templates.

          Thanks for your expert advice.

          --Greg.

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

          Comment

          Working...
          X