Using ONLY the PEEK function, how would I be able to extract the information of the array descriptor and print each elements. This procedure should be able to print the elements of the array regardless if its 1, 2, or more dimensions.
Example:
DIM Array1$r(1 to 5)
Array1$r(1) = "orange"
Array1$r(2) = "apples"
Array1$r(3) = "pear"
Array1$r(4) = "pineapple"
Array1$r(5) = "orange"
Call PrintArray ( Array1$() )
DIM Array2$r(1 to 5, 1 to 25)
Array2$r(1, 1) = "orange"
.
.
.
Array2$r(5, 25) = "orange"
Call PrintArray ( Array2$() )
Sub PrintArray (Array$())
'-- print the elements regardless what the dimension of the array is
End Sub
Array Descriptor
Not quite sure why you would want to do that but you will probably want to use SADD(Array$(1)) to find the first memory address of the given element and then use PEEK a statement in a loop to get the string.
If you are just trying to access arrays in a sub you could just use DIM SHARED
Code: Select all
DECLARE SUB PrintString (Addr AS INTEGER, NextAddr AS INTEGER)
DIM Array(3) AS STRING
Array(1) = "String 1"
Array(2) = "String 2"
CALL PrintString(SADD(dunno(1)), SADD(dunno(2)))
SUB PrintString (Addr AS INTEGER, NextAddr AS INTEGER)
Position = Addr
NewString$ = ""
DO
IF NextAddr = Position THEN EXIT DO
NewString$ = NewString$ + CHR$(PEEK(Position))
Position = Position + 1
IF PEEK(Position) = 34 THEN EXIT DO
IF PEEK(Position) = 46 THEN EXIT DO
IF PEEK(Position) = 249 THEN EXIT DO
IF PEEK(Position) < 32 THEN EXIT DO
IF NextAddr = Position THEN EXIT DO
LOOP
PRINT NewString$
END SUB
- DDastardly71
- Coder
- Posts: 22
- Joined: Fri Oct 17, 2008 6:56 pm
- Location: U.S.A.
Thanks for that reply but that won't work.
Even with fixed length string array you still have to set the correct segment before you can peek at the memory.
I know this is unorthodox way of doing it when I could easily just pass the array into the procedure. I wrote a user interface function in PDS for DOS where it will load a custom screen file that includes the screen image and the field definitions.
In this function I'm using a user define type field record and if there are notes fields, i would assign the segment/address of that array and assign it to the user defined element so that I only pass one record to the function.
I have no problem displaying the elements of a variable string array using NEAR string but FAR string is a bit more complex.
I'm using the Ethan Winer example in his book "BASIC Techniques & Utilities" where he uses the following array descriptor..i just cant seem to make it work.
Even with fixed length string array you still have to set the correct segment before you can peek at the memory.
I know this is unorthodox way of doing it when I could easily just pass the array into the procedure. I wrote a user interface function in PDS for DOS where it will load a custom screen file that includes the screen image and the field definitions.
In this function I'm using a user define type field record and if there are notes fields, i would assign the segment/address of that array and assign it to the user defined element so that I only pass one record to the function.
Code: Select all
dim Fld(25) as FieldInfo
dim notes$(1 to 15)
Fld(5).NotesSegment = SSEG(notes$(1))
Fld(5).NotesAddress = SADD(notes$(1))
DO
FormEdit Fld()
.
.
LOOP
I'm using the Ethan Winer example in his book "BASIC Techniques & Utilities" where he uses the following array descriptor..i just cant seem to make it work.
Code: Select all
Offset Size Description
------- ----- ----------------------------------------------------
00 02 Address where array data begins
00 02 Segment where that address resides
04 02 Far heap descriptor, pointer
06 02 Far heap descriptor, block size
08 01 Number of dimensions in the array
09 01 Array type and storage method:
Bit 0 set = far array
Bit 1 set = huge (/ah) array
Bit 6 set = static array
Bit 7 set = string array
0A 02 Adjusted Offset
0C 02 Length in bytes of each element
0E 02 Number of elements in the last
dimension (UBOUND - LBOUND + 1)
10 02 First element number in that
dimension (LBOUND)
12 02 Number of elements in the second
from last dimension
14 02 First element number in that
dimension
. 02 Repeat number of elements and
first element number as necessary,
. 02 through the first dimension