PBCC - DATA OVERLAYS 
Author Message
 PBCC - DATA OVERLAYS

I have a basic understanding of TYPE & UNION functions. How would one go
about doing the following:

       If i read a Customer Record into a TYPE Function:

            TYPE CUSTREC
                    CUSTOMER#     AS     LONG
                    CUSTNAME        AS     STRING * 30
                    CUSTSTREET    AS     STRING * 25
                    CUSTCITY           AS     STRING * 15
                    CUSTSTATE        AS    STRING * 2
                    CUSTZIP               AS   STRING * 10
          END TYPE
            DIM MASTER AS CUSTREC

        Is there any way to overlay the Street,City,State,Zip as several
other fields.
    This may not be good example but I may want to use this area to store
different information other than the street,city,state,zip - perhaps:

                SOMEVALUE1        AS        QUAD
                SOMEVALUE2        AS        QUAD
                SOMEVALUE3        AS        QUAD
                SOMEALPHA         AS        STRING * 40
                SOMEALPHA2        AS        STRING * 22



Sat, 15 Nov 2003 08:14:33 GMT  
 PBCC - DATA OVERLAYS
Well, you can use a union to do this, but one of things you'll need to do in
this case is be able to identify which kind of record you are looking at.

The idea of a union is that the same memory may hold different types of data
depending on circumstance; however, it is the programmer's responsibility to
keep track of what is in that space at any one time, and only one "type" of
data may occupy that space at any one time.

Here is an example from my article, " A More Perfect Union" published in the
Aptril, 1996 issue of "BASICally Speaking " magazine:

TYPE SystemTimeType
 HH AS STRING * 2
 Colon1 AS STRING * 1
  MM       AS STRING * 2
 Colon2  AS STRING * 1
 SS AS   STRING * 2
END TYPE

UNION TimeUnion
  TypeTime AS SystemTimeType
  StringTime AS STRING * 8
END UNION

Dim Foo AS TimeUnion
LSET Foo.StringTime = TIME$       ' << puts "HH:MM:SS" into Foo.StringTime

' print the formatted time using the redefinition provided by the UNION
PRINT "The time is ";Foo.TypeTime.HH; " hours "; Foo.TypeTime.MM; " minutes
and ";Foo.TypeTime.SS; " seconds"
END

So, the answer is, yes, you can use the same memory space to define multiple
record types, or even to redefine fields within a record, but you need to
carefully define the data.

The text of the article (well, you'd get the whole issue) is available from
the publisher, Information Mangagement Systems at www.infoms.com. Follow the
links to "Basically Speaking". It will cost you $4.00.

The code  (there's lots more UNION code) is available in the "archives" at
this IMS site; the source code is public domain.

--
Michael C. Mattias
Tal Systems
Racine WI


Quote:
> I have a basic understanding of TYPE & UNION functions. How would one go
> about doing the following:



Sat, 15 Nov 2003 21:25:23 GMT  
 PBCC - DATA OVERLAYS

Quote:

>I have a basic understanding of TYPE & UNION functions. How would one go
>about doing the following:

>       If i read a Customer Record into a TYPE Function:

>            TYPE CUSTREC
>              CUSTOMER#  AS LONG
>              CUSTNAME   AS STRING * 30
>              CUSTSTREET AS STRING * 25
>              CUSTCITY   AS STRING * 15
>              CUSTSTATE  AS STRING * 2
>              CUSTZIP    AS STRING * 10
>            END TYPE
>            DIM MASTER AS CUSTREC

>        Is there any way to overlay the Street,City,State,Zip as several
>other fields.
>    This may not be good example but I may want to use this area to store
>different information other than the street,city,state,zip - perhaps:

>                SOMEVALUE1        AS        QUAD
>                SOMEVALUE2        AS        QUAD
>                SOMEVALUE3        AS        QUAD
>                SOMEALPHA         AS        STRING * 40
>                SOMEALPHA2        AS        STRING * 22

Sure. All you're doing is storing bytes of data. In this case there are 52?
bytes so

TYPE CustRec
  CustNbr   AS LONG
  CustName  AS STRING * 30
  OtherData AS STRING * 52
END TYPE

TYPE CustAddress
  Street AS STRING * 30
  City   AS STRING * 15
  State  AS STRING *  2
  Zip    AS STRING * 10
END TYPE

TYPE Whatever
  SomeVal1 AS QUAD
  SomeVal2 AS QUAD
  SomeVal3 AS QUAD
END TYPE

DIM tCust    AS CustRec
DIM tAddress AS CustAddress
DIM tOther   AS Whatever

tAddress = tCust.OtherData

-- OR --

tOther   = tCust.OtherData

-- or --

If it is easier for you simply defind 2 complete structures that can use the
same record.

--
C'ya,

  Don Schullian
www.DASoftVSS.com
www.basicguru.com



Sat, 15 Nov 2003 21:46:08 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Data Overlays

2. How to start app minimized or hidden in PBCC 3.0

3. Windows API calls and pbcc

4. how can I make functions in PBCC ?

5. PBCC graphics

6. PBCC question

7. PBCC and physical memory

8. PBCC Shock and Outrage

9. pbcc formfeeds

10. LPRINT PBCC 1.0

11. Get a copy of PBCC 6.0

12. Mouse disabled during redirect (PBCC)

 

 
Powered by phpBB® Forum Software