PDS (7.1) Procedures - mkilgore/QB64pe GitHub Wiki

QB64 is created to be compatible with Quick Basic 4.5 only as it was the most popular version. The following sub-procedures have been created to do things that were available in PDS versions of Quick Basic 7.0 and 7.1:

Table of Contents

CURRENCY

MKC$

PDS could use the CURRENCY variable type and had the MKC$ function to convert those values to 8 byte ASCII string values. QB64 can convert _FLOAT currency amounts to strings using _MK$ with _INTEGER64 values:

SCREEN 12
DIM value AS _FLOAT
value = 12345678901234.6789 '    any currency value with up to 4 decimal point places

_PRINTSTRING (1, 50), "[" + MKC$(value) + "]" ' show ASCII string value

END

FUNCTION MKC$ (CurrVal AS _FLOAT) 'converts currency amount to PDS or VB currency string
DIM CVal AS _INTEGER64
CVal = CurrVal * 10000 '        multiply float value by 10 thousand
MKC = _MK$(_INTEGER64, CVal)
END FUNCTION '' ''
Note: The _FLOAT currency amount must be multiplied by 10000 before it is converted to the ASCII string value.

CVC

PDS also had the CVC function to convert MKC$ currency string values back to currency amounts. QB64 can use _CV with _INTEGER64 to convert those 8 byte values back to _FLOAT currency values. The procedure gets the currency string from a file:

_PRINTSTRING (1, 10), "[" + currency + "]" 'show ASCII string value from file

_PRINTSTRING (1, 30), STR$(CVC##(currency))

END

FUNCTION CVC## (CurrStr AS STRING) 'converts currency string to a _FLOAT currency amount
DIM CV AS _INTEGER64
CV = _CV(_INTEGER64, CurrStr)
CVC = CV / 10000 '                   divide by 10 thousand
END FUNCTION '' ''
Note: The _FLOAT currency amount must be divided by 10000 to create up to 4 decimal point places.

PUT

Currency values can be PUT directly into BINARY or RANDOM files using an _INTEGER64 variable value.

currency = 9876.543
curr = currency * 10000 ' multiply currency value by 10000

OPEN "currency.bin" FOR...NEXT BINARY AS #1 ' a binary file to hold PDS currency values
PUT #1, , curr
CLOSE #1

END '' ''

GET

When currency values are PUT directly into a BINARY or RANDOM file, _INTEGER64 can GET them directly. Then divide by 10 ^ 4:

currency = curr / 10000 ' use any floating decimal point type within currency range

PRINT currency

END '' ''
Note: The currency value can be any SINGLE, DOUBLE or _FLOAT floating decimal point value that will hold the range of values.

(Return to Table of Contents)

DIR$

Not to be confused with QB64's _DIR$ function.

This PDS(7.1) derived DIR$ function returns a filename or a list when more than one exist. The file spec can use a path and/or wildcards.

END

FUNCTION DIR$ (spec$)
CONST TmpFile$ = "DIR$INF0.INF", ListMAX% = 500 'change maximum to suit your needs
SHARED '''DIRCount% 'returns file count if desired. MAY conflict with user's existing code'''
STATIC Ready%, Index%, DirList$()
IF...THEN NOT Ready% THEN REDIM DirList$(ListMAX%): Ready% = -1 'DIM array first use
IF...THEN spec$ > "" THEN 'get file names when a spec is given
  SHELL _HIDE "DIR " + spec$ + " /b > " + TmpFile$
  Index% = 0: DirList$(Index%) = "": ff% = FREEFILE
  OPEN TmpFile$ FOR...NEXT APPEND AS #ff%
  size& = LOF(ff%)
  CLOSE #ff%
  IF...THEN size& = 0 THEN KILL TmpFile$: EXIT FUNCTION
  OPEN TmpFile$ FOR (file statement) INPUT (file mode) AS #ff%
  DO...LOOP WHILE NOT EOF(ff%) AND (boolean) Index% < ListMAX%
    Index% = Index% + 1
    LINE INPUT (file statement) #ff%, DirList$(Index%)
  LOOP
  DIRCount% = Index% 'SHARED variable can return the file count
  CLOSE #ff%
  KILL TmpFile$
ELSE IF...THEN Index% > 0 THEN Index% = Index% - 1 'no spec sends next file name
END IF
DIR$ = DirList$(Index%)
END FUNCTION '' ''
Code by Ted Weissgerber
Explanation: The function will verify that a file exists (even if it is empty) by returning it's name or it returns an empty string if no file exists. It can return a list of file names by using an empty string parameter("") after sending a wildcard spec to get the first file name. The number of file names found is returned by using the SHARED variable, DIRCount%. Unlike the PDS DIR$ function, it MUST use an empty string parameter until QB64 supports optional parameters! The function does NOT delete empty files.

(Return to Table of Contents)

References

See also:


Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
⚠️ **GitHub.com Fallback** ⚠️