Category : Databases and related files
Archive   : BTRV410.ZIP
Filename : B_DEMO.CLA

 
Output of file : B_DEMO.CLA contained in archive : BTRV410.ZIP
B_DEMO PROGRAM !DEMO BTRIEVE.BIN
MAP
FUNC(PageSize),LONG !PAGE SIZE CALCULATOR
INCLUDE('BTRIEVE.CPY'),LIST !BTRIEVE FUNCTION DEFINITION
.

! * * * * Calling Convention * * * *
!
! Status = Btrieve(OpCode,PosBlk,DataBuf,DataLen,KeyBuf,KeyNum)
!
! * * * * Parameter Descriptions * * * *
!
! Status - Returned status from operation.
! If non-zero, Status may be used as an index into
! the array of error descriptions.
! See BTRIEVE.ERR
!
! OpCode - Operation to be performed.
! See BTRIEVE.OP
!
! PosBlk - A 128 byte buffer area that is FILE UNIQUE!
! * * * DO NOT MODIFY AFTER INITIALIZATION * *
! Can be STRING(128) or BYTE,DIM(128).
!
! DataBuf - A user defined area like a Clarion RECORD.
! Usually a GROUP structure label.
!
! DataLen - Length of DataBuf structure.
! Cannot exceed SHORT value (65535).
!
! KeyBuf - Buffer for KEY information.
! Size is dependent on key structure.
!
! KeyNum - Key number being accessed.
! A numeric value dependent on record PAGE SIZE.
! For 512 byte page, range is 0..7
! For 1024 byte page, range is 0..23
!
INCLUDE('BTRIEVE.ERR'),LIST !ERROR DESCRIPTIONS
INCLUDE('BTRIEVE.OP'),LIST !OPERATION CODES
INCLUDE('BTRIEVE.CRE'),LIST !FOR CREATING FILES

ibStatus BYTE !RETURNED STATUS

PosBlk STRING(128) !FILE UNIQUE, DO NOT CHANGE !!

DataBuf GROUP !BTRIEVE 'RECORD' BUFFER
Lname STRING(30)
Fname STRING(20)
Phone STRING(@P###-####P)
.
DataLen SHORT
LnameKey STRING(30) !KEYING ON LAST NAME ONLY
FullNameKey STRING(50) !KEYING ON FULL NAME
PhoneKey STRING(8) !KEYING ON PHONE NUMBER
SCREEN SCREEN HUE(7,1)
.
CODE
OPEN(SCREEN)
DataLen = SIZE(DataBuf) !GET SIZE OF DATA BUFFER

! FIRST, ATTEMPT TO OPEN THE FILE
! NOTICE THAT FILENAME IS TERMINATED WITH A <0> (A space will work also)
ibStatus = Btrieve(bOpen,PosBlk,DataBuf,DataLen,'B_DEMO.DAT<0>',0)

IF ibStatus = 12 !IF 'FILE NOT FOUND' ERROR
CLEAR(bFileSpec) ! START BY CLEARING THE GROUP
bRecLength = SIZE(DataBuf) ! FILL IN RECORD LENGTH
bPageSize = PageSize(bRecLength,,1) ! GET BEST FIT PAGE SIZE
STOP(bPageSize)
bNumIndexes = 3 ! 3 KEYS IN THIS FILE
bFileFlags = 0 ! NOTHING SPECIAL ABOUT FILE
bAllocation = 0 ! NO PRE-ALLOCATED PAGES
! Start filling in KEY information.
CLEAR(bKeySpecs[]) ! START BY ERASING THE GROUP

bKeyPosition[1] = 1 ! LnameKey STARTS AT BYTE 1
bKeyLength[1] = SIZE(LnameKey) ! FILL IN LENGTH OF KEY
bKeyFlags[1] = 11 ! DUP+MOD+NULL
bExtendedKey[1] = 0 ! NO EXTENDED KEYS

bKeyPosition[2] = 1 ! FullNameKey STARTS AT BYTE 1
bKeyLength[2] = SIZE(FullNameKey) ! FILL IN LENGTH OF KEY
bKeyFlags[2] = 2 ! MOD+NULL
bExtendedKey[2] = 0 ! NO EXTENDED KEYS

bKeyPosition[3] = 51 ! PhoneKey STARTS AT BYTE 51
bKeyLength[3] = SIZE(PhoneKey) ! FILL IN LENGTH OF KEY
bKeyFlags[3] = 10 ! MOD+NULL
bExtendedKey[3] = 0 ! NO EXTENDED KEYS
ibStatus = Btrieve(bCreate,PosBlk,bFileSpec,SIZE(bFileSpec), |
'B_DEMO.DAT<0>',0)
IF ibStatus THEN STOP('Had Error '&ibStatus&' creating file.').
ibStatus = Btrieve(bClose,PosBlk,DataBuf,DataLen,FullNameKey,0)
IF ibStatus THEN STOP('Had Error '&ibStatus&' closing file.').
ibStatus = Btrieve(bOpen,PosBlk,DataBuf,DataLen,'B_DEMO.DAT<0>',0)
IF ibStatus THEN STOP('Had Error '&ibStatus&' opening file.').
ELSIF ibStatus !OTHERWISE, IF OTHER ERROR
STOP(BtrvError[ibStatus]) ! STOP SHOWING ERROR STRING
RETURN
.
ibStatus = Btrieve(bClose,PosBlk,DataBuf,DataLen,FullNameKey,0)
IF ibStatus THEN STOP('Had Error '&ibStatus&' closing file.').


PageSize FUNCTION(RecLen,Variable,Dups)
OMIT('* * Function Description * *')
ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ PageSize determines a 'best-fit' page size for your record. The page size ³
³ will be between 512 and 4096 bytes in increments of 512 bytes. This function ³
³ will choose the page size that leaves as little 'unused' area in a page as ³
³ possible. The computational method was taken from the Btrieve 4.10 manual. ³
ÆÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͵
³ Input parameters: ³
³ RecLen - The actual size of your data record. ³
³ Variable - Set to TRUE (1) if you intend to have variable length records. ³
³ Dups - Pass the number of DUPLICATE KEYS your file will contain. ³
ÆÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͵
³ Note: EXTERNAL parameters need not be passed if they are not relevent. ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
* * Function Description * *
RecLen SHORT !SIZE OF REGULAR RECORD BUFFER
Variable EXTERNAL !TRUE/FALSE VARIABLE LENGTH
Dups EXTERNAL !NUMBER OF DUPLICATE KEYS
isRecLength SHORT !COMPUTED LENGTH-OF-RECORD
tPageSize TABLE,PRE(tPS)
isPageSize SHORT !RESULTANT PAGE SIZE
isUnUsed SHORT !UNUSED AMOUNT PER PAGE-SIZE
.
CODE
isRecLength = RecLen !START WITH SIZE OF BUFFER
IF ~OMITTED(2) !IF 'Variable' WAS PASSED
IF Variable THEN isRecLength += 4. ! ADD 4 BYTES IF VARIABLE RECS
.
IF ~OMITTED(3) !IF 'Dups' WAS PASSED
isRecLength += (Dups*8) ! ADD 8 BYTES FOR EACH DUP KEY
.
! isRecLength NOW HAS ADJUSTED RECORD LENGTH
LOOP Size# = 512 TO 4096 BY 512 !LOOP THRU EACH PAGE SIZE
NumRecs# = 1 !START WITH 1 RECORD/PAGE
LOOP !LOOP TO FIND MAX RECS/PAGE
IF (isRecLength*(NumRecs#+1)) > Size# THEN BREAK.
NumRecs# += 1
.
tPS:isPageSize = Size# !PUT PAGE SIZE IN TABLE
tPS:isUnUsed = Size#-(isRecLength*NumRecs#) !PUT UNUSED SIZE IN TABLE
ADD(tPageSize) !ADD RECORD TO TABLE
. !END LOOP
SORT(tPageSize,tPS:isUnUsed) !SORT TABLE BY UNUSED SIZE
GET(tPageSize,1) !GET THE FIRST RECORD (LEAST)
BestFit# = tPS:isPageSize !THIS IS THE 'BEST FIT' SIZE
FREE(tPageSize) !EMPTY THE TABLE
RETURN(BestFit#) !RETURN THE BEST FIT SIZE PAGE


  3 Responses to “Category : Databases and related files
Archive   : BTRV410.ZIP
Filename : B_DEMO.CLA

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/