'Simulating an integer array within a TYPE 'by Dave Navarro, Jr.
DEFINT A-Z
TYPE MyType
name AS STRING * 30
' x(5) AS INTEGER ' QuickBASIC/PDS
x AS STRING * 10 ' PowerBASIC: 5 integers is 10 bytes END TYPE
DIM TestMe AS MyType
TestMe.x = STRING$(10, 0) 'clear array to zeros
PutElement TestMe.x, 15, 2 'put the value 15 at element #2
PRINT GetElement(TestMe.x, 2) 'print the value of element #2
SUB PutElement(ANY, BYVAL value%, BYVAL element%)
! push DS ; save DS for PowerBASIC
! mov AX, element% ; put element number in AX
! dec AX ; make it zero-based
! shl AX, 1 ; times 2 for offset
! les DI, [BP+10] ; point ES:DI to start of array
! add DI, AX ; point DI at desired element
! mov AX, value% ; get value to store
! mov ES:[DI], AX ; store it
! pop DS ; restore DS
END SUB
FUNCTION GetElement%(ANY, BYVAL element%)
! push DS ; save DS for PowerBASIC
! mov AX, element% ; put element number in AX
! dec AX ; make it zero-based
! shl AX, 1 ; times 2 for offset
! les DI, [BP+8] ; point ES:DI to start of array
! add DI, AX ; point DI at desired element
! mov AX, ES:[DI] ; get element value
! mov FUNCTION, AX ; return it to calling program
! pop DS ; restore DS
END FUNCTION
---
* QMPro 1.53 * It's not hard to meet expenses, they're everywhere.
--- InterEcho 1.18
---------------
* Origin: Toast House * (314) 994-0312 * (1:100/560)
|