BBS: Inland Empire Archive Date: 02-09-93 (16:56) Number: 327 From: QUINN TYLER JACKSON Refer#: NONE To: ALL Recvd: NO Subj: EMS Array Code 1/ Conf: (2) Quik_Bas
' Here is some code I posted a while back. Thought it might give the
' echo a bit of a code boost...
DECLARE FUNCTION IsAllASCII (Txt$) AS INTEGER
' JackMack SuperArray Management Kit v1.0
' Released into the public domain on 24 December 1992
' in the interest of mutually beneficial programming practices.
' Rereleased February 1993
' Written by Quinn Tyler Jackson of
' JackMack Consulting & Development
' "Specializing in Custom DOS-based GUI applications and on-line
' documentation."
' This array management tool is programmed for VBDOS 1.0, but may
' be fully compatible with BASIC PDS 7.x. It uses advanced features
' not found in QuickBASIC 4.5, but these features MAY be worked out
' by enterprising programmers. Words to look for in the source code
' include: PRESERVE.
' Features of this application:
' INTEGER and LONG numeric arrays can be stored in EMS memory, leaving
' space free for bigger and better things. Arrays are referenced not by
' obscure numbers and handles, but by user assigned names that may include
' ANY character. That means that an array COULD conceivably be called
' "This is my array."
' STRING arrays are stored to a to virtual memory file, and are variable
' length. Only their pointers are stored in RAM, and even these are stored
' safely out of the way in EMS. In short, as long as disk space allows,
' one could have a 300,000 element string array, each element being between
' one and 32000 some odd characters long, and it wouldn't take up any more
' of DGROUP or far string space than any other STRING JmArray.
' Also note that STRING arrays are compressed onto the virtual disk file
' if they do not contain high-ASCII characters, to conserve disk space.
' Some academic points illustrated by this program:
' 1) Pointer referencing,
' 2) End user modifiable array names,
' 3) "Handle-based" arrays,
' 4) Virtual memory.
' NOTE: To allow for INTEGER and LONG values to be passed back from the
' same function that returns STRING values, all values are passed
' back as STRING. They must be converted thus:
'
' ErrorCode = JmSET ("My array", 10, "100")
' IntegerValue = VAL(JmGet ("My array",10)
'
' This is unfortunate, but allows one function to return ALL types
' of data, not just one per function.
' These seven routines are from Hanlin's PBCLONE 1.9 library. Earlier
' versions of PBCLONE might work, too.
DECLARE FUNCTION IsASCII% (Ch$)
DECLARE FUNCTION StrSqu$ (St$)
DECLARE FUNCTION StrUnSq$ (St$)
DECLARE SUB EMSClose (BYVAL ArrayHandle%)
DECLARE SUB EMSOpen (Elements&, ElementType%, ArrayHandle%, ErrCode%)
DECLARE SUB EMSGet (BYVAL ArrayHandle%, ElementNr&, Value AS ANY)
DECLARE SUB EMSPut (BYVAL ArrayHandle%, ElementNr&, Value AS ANY)
' These routines are local to this particular program.
DECLARE FUNCTION JmGET$ (ArrayName$, Element AS LONG, ErrCode AS INTEGER)
DECLARE FUNCTION JmDIM% (ArrayName$, Elements AS LONG, ArrayType%)
DECLARE FUNCTION JmWORD (InExpression$, Index%) AS STRING
DECLARE FUNCTION JmSET% (ArrayName$, Element AS LONG, Vlue AS STRING)
DECLARE FUNCTION JmERASE% (ArrayName$)
OPTION BASE 1 ' I prefer things to start at one. Humans tend to count that
' way, don't you agree?
'Some system constants.
CONST BUFFER_MAX = 10 ' How many previously read strings to buffer.
CONST VirtualFile = "JMVSA.$$$" ' Virtual string memory file.
CONST StartSize = 10
'Ye olde tradional Boolean logic constants
CONST TRUE = (1 = 1) ' I prefer (1=1) since it is compiler
' independent, whereas -1 is specific to
' MS BASICS.
CONST FALSE = NOT TRUE
' Array Types
CONST Array_Integer = 1
CONST Array_Long = 2
CONST Array_String = 3
' Errors that might happen
CONST Err_EMS_Allocation = -1
CONST Err_Bad_Subscript = -2
CONST Err_Array_Not_Dimensioned = -3
CONST Err_Overflow = -4
CONST Err_DOS_Error = -5
' PointerType for the array cross-reference table.
TYPE PointerType
Elements AS LONG ' How many array elements array has.
Handle AS INTEGER ' EMS handle of either data or ptr table
' (String arrays use an EMS ptr table).
ArrayType AS INTEGER ' What type of array we're dealing with.
Accesses AS LONG ' How many times this array is accessed.
END TYPE
DEFINT A-Z
'$DYNAMIC arrays are going to be used so they can be redimensioned.
' PtrArray changes size and must be preserved when it does so. Therefore,
' QuickBASIC users might have to rethink the logic I have used throughout.
DIM SHARED PtrArray(StartSize) AS PointerType
REDIM SHARED AName$(StartSize) ' Names of arrays.
DIM SHARED VirtualHandle AS INTEGER ' Handle of virtual memory file.
' The simple sample application to show syntax follows here. Normally, your
' program would go here....
CLS
' A 300,000 element string array! Requires lots of EMS for pointers! A
' one million element array would require 4 Megs of free EMS, but wouldn't
' take up any more DGROUP or conventional memory than a two element array!
INPUT "This array can have any name you'd like: ", Array$
' Arrays can be named at the end-user level. This is good for database
' applications and is a powerful feature. The user is not forced to refer
' to his specific data by any contrived name other than the one he or she
' assigns!
nul = JmDIM(Array$, 1000, Array_String)
IF nul < 0 THEN PRINT "ERROR": END
PRINT nul
PRINT "Getting data from array '" + Array$ + "'."
nul = JmSET(Array$, 1000, "This is a test. The test seems to have worked.")
PRINT JmGET(Array$, 1000, ErrCode)
nul = JmERASE("*") 'Be sure to do this to free EMS handles and memory!
>>> Continued to next message
* SLMR 2.1a *
--- Maximus 2.01wb
* Origin: VKUG/VPCC QuickBasic Echo - Richmond, BC (1:153/151)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET