PDS(7.1) Procedures: Difference between revisions
Jump to navigation
Jump to search
Attention!! - This function is outdated and provided for reference and/or education only.
Starting with QB64-PE v3.4.0 the functionality described here was superseded by _OPENFILEDIALOG$.
Additionally since QB64-PE v3.11.0 _FILES$ can be used to read file names programmatically.
Code by Ted Weissgerber
Wiki Pages
Main Page with Articles and Tutorials
QB64 specific keywords (alphabetical)
Original QBasic keywords (alphabetical)
QB64 OpenGL keywords (alphabetical)
Keywords by Usage
Got a question about something?
Frequently Asked Questions about QB64
QB64 Phoenix Edition Community Forum
Links to other QBasic Sites:
Pete's QBasic Forum
Pete's QBasic Downloads
No edit summary |
No edit summary |
||
(18 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
QB64 was created to be compatible with | {| align="right" style="max-width:25%;" | ||
| __TOC__ | |||
|} | |||
'''QB64''' was created to be compatible with '''QB 4.5 or lower''' versions. '''PDS(7.1) is not supported'''. The following sub-procedures have been created to do things that were available in '''PDS''' versions of '''QuickBASIC 7.0 and 7.1'''. | |||
== CURRENCY == | |||
===MKC$=== | === MKC$ === | ||
PDS could use the CURRENCY variable type and had the MKC$ function to convert those values | :* PDS could use the '''CURRENCY''' variable type and had the '''MKC$''' function to convert those values into 8 byte [[ASCII]] string values. | ||
:* QB64 can convert [[_FLOAT]] currency amounts to strings using [[_MK$]] with [[_INTEGER64]] values: | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} 12 | {{Cl|SCREEN}} 12 | ||
{{Cl|DIM}} value {{Cl|AS}} {{Cl|_FLOAT}} | {{Cl|DIM}} value {{Cl|AS}} {{Cl|_FLOAT}} | ||
value = 12345678901234.6789 ' | value = 12345678901234.6789 'any currency value with up to 4 decimal point places | ||
{{Cl|_PRINTSTRING}} (1, 50), "[" + MKC$(value) + "]" 'show ASCII string value | |||
{{Cl|END}} | {{Cl|END}} | ||
{{Cl|FUNCTION}} MKC$ (CurrVal {{Cl|AS}} {{Cl|_FLOAT}}) | '----------------------------------------------- | ||
'converts currency amount to PDS currency string | |||
'----------------------------------------------- | |||
{{Cl|FUNCTION}} MKC$ (CurrVal {{Cl|AS}} {{Cl|_FLOAT}}) | |||
{{Cl|DIM}} CVal {{Cl|AS}} {{Cl|_INTEGER64}} | {{Cl|DIM}} CVal {{Cl|AS}} {{Cl|_INTEGER64}} | ||
CVal = CurrVal * 10000 | CVal = CurrVal * 10000 | ||
MKC = {{Cl|_MK$}}({{Cl|_INTEGER64}}, CVal) | MKC$ = {{Cl|_MK$}}({{Cl|_INTEGER64}}, CVal) | ||
{{Cl|END FUNCTION}} | {{Cl|END FUNCTION}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
;Note:The [[_FLOAT]] currency amount must be multiplied by 10000 before it is converted to the [[ASCII]] string value. | |||
---- | |||
===CVC=== | === 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 | :* 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. | |||
:** In this example the procedure gets the currency string from a file. | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} 12 | {{Cl|SCREEN}} 12 | ||
{{Cl|DIM}} currency {{Cl|AS}} {{Cl|STRING}} * 8 | {{Cl|DIM}} currency {{Cl|AS}} {{Cl|STRING}} * 8 | ||
{{Cl|OPEN}} " | {{Cl|OPEN}} "currency.bin" {{Cl|FOR (file statement)|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 'binary file with MKC$ values created by PDS | ||
{{Cl|GET}} #1, , currency | {{Cl|GET}} #1, , currency | ||
{{Cl|CLOSE}} #1 | {{Cl|CLOSE}} #1 | ||
{{Cl|_PRINTSTRING}} (1, 10), "[" + currency + "]" 'show ASCII string value from file | {{Cl|_PRINTSTRING}} (1, 10), "[" + currency + "]" 'show ASCII string value from file | ||
{{Cl|_PRINTSTRING}} (1, 30), {{Cl|STR$}}(CVC##(currency)) | {{Cl|_PRINTSTRING}} (1, 30), {{Cl|STR$}}(CVC##(currency)) | ||
{{Cl|END}} | {{Cl|END}} | ||
{{Cl|FUNCTION}} CVC## (CurrStr {{Cl|AS}} {{Cl|STRING}}) | '----------------------------------------------------------- | ||
'converts currency string to a {{Cl|_FLOAT}} currency amount | |||
'----------------------------------------------------------- | |||
{{Cl|FUNCTION}} CVC## (CurrStr {{Cl|AS}} {{Cl|STRING}}) | |||
{{Cl|DIM}} CV {{Cl|AS}} {{Cl|_INTEGER64}} | {{Cl|DIM}} CV {{Cl|AS}} {{Cl|_INTEGER64}} | ||
CV = {{Cl|_CV}}({{Cl|_INTEGER64}}, CurrStr) | CV = {{Cl|_CV}}({{Cl|_INTEGER64}}, CurrStr) | ||
CVC = CV / 10000 | CVC## = CV / 10000 | ||
{{Cl|END FUNCTION}} | {{Cl|END FUNCTION}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
;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. | |||
:** Remember to multiply the currency value by 10000 before putting to file. | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|DIM}} curr {{Cl|AS}} {{Cl|_INTEGER64}}, currency {{Cl|AS}} {{Cl|_FLOAT}} | {{Cl|DIM}} curr {{Cl|AS}} {{Cl|_INTEGER64}}, currency {{Cl|AS}} {{Cl|_FLOAT}} | ||
currency = 9876.543 | currency = 9876.543 | ||
curr = currency * 10000 ' multiply currency value | curr = currency * 10000 'multiply currency value | ||
{{Cl|OPEN}} "currency.bin" {{Cl|FOR (file statement)|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 ' a binary file to hold PDS currency values | {{Cl|OPEN}} "currency.bin" {{Cl|FOR (file statement)|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 'a binary file to hold PDS currency values | ||
{{Cl|PUT}} #1, , curr | {{Cl|PUT}} #1, , curr | ||
{{Cl|CLOSE}} #1 | {{Cl|CLOSE}} #1 | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
===GET=== | ---- | ||
When currency values are [[PUT]] directly into a [[BINARY]] or [[RANDOM]] file, [[_INTEGER64]] can [[GET]] them directly. | |||
=== GET === | |||
:* When currency values are [[PUT]] directly into a [[BINARY]] or [[RANDOM]] file, [[_INTEGER64]] can [[GET]] them directly. | |||
:** Remember to divide the currency value by 10000 after getting from file. | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|DIM}} curr {{Cl|AS}} {{Cl|_INTEGER64}}, currency {{Cl|AS}} {{Cl|_FLOAT}} | {{Cl|DIM}} curr {{Cl|AS}} {{Cl|_INTEGER64}}, currency {{Cl|AS}} {{Cl|_FLOAT}} | ||
{{Cl|OPEN}} "currency.bin" {{Cl|FOR (file statement)|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 ' any binary file holding PDS currency values | {{Cl|OPEN}} "currency.bin" {{Cl|FOR (file statement)|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 'any binary file holding PDS currency values | ||
{{Cl|GET}} #1, , curr | {{Cl|GET}} #1, , curr | ||
{{Cl|CLOSE}} #1 | {{Cl|CLOSE}} #1 | ||
Line 73: | Line 88: | ||
{{Cl|PRINT}} currency | {{Cl|PRINT}} currency | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
;Note:The currency value can be any [[SINGLE]], [[DOUBLE]] or [[_FLOAT]] floating decimal point value that will hold the range of values. | |||
<p style="text-align: center">([[#top|Return to Table of Contents]])</p> | |||
== DIR$ == | |||
;{{Text|Attention|red}}:'''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 specification (''spec$'') can use a path and/or wildcards. | |||
---- | |||
'' | ---- | ||
<center>'''{{Text|Attention!! - This function is outdated and provided for reference and/or education only.|red}}'''</center> | |||
---- | |||
<center>Starting with '''QB64-PE v3.4.0''' the functionality described here was superseded by [[_OPENFILEDIALOG$]].</center> | |||
<center>Additionally since '''QB64-PE v3.11.0''' [[_FILES$]] can be used to read file names programmatically.</center> | |||
---- | |||
---- | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} 2 | {{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} 2 | ||
Line 99: | Line 124: | ||
{{Cl|END IF}} | {{Cl|END IF}} | ||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
{{Cl|END}} | {{Cl|END}} | ||
{{Cl|FUNCTION}} DIR$ (spec$) | {{Cl|FUNCTION}} DIR$ (spec$) | ||
{{Cl|CONST}} TmpFile$ = "DIR$INF0.INF", ListMAX% = 500 'change maximum to suit your needs | {{Cl|CONST}} TmpFile$ = "DIR$INF0.INF", ListMAX% = 500 'change maximum to suit your needs | ||
{{Cl|SHARED}} | {{Cl|SHARED}} DIRCount% 'returns file count if desired. | ||
{{Cl|STATIC}} Ready%, Index%, DirList$() | {{Cl|STATIC}} Ready%, Index%, DirList$() | ||
{{Cl|IF...THEN|IF}} {{Cl|NOT}} Ready% {{Cl|THEN}} {{Cl|REDIM}} DirList$(ListMAX%): Ready% = -1 '{{Cl|DIM}} array first use | {{Cl|IF...THEN|IF}} {{Cl|NOT}} Ready% {{Cl|THEN}} {{Cl|REDIM}} DirList$(ListMAX%): Ready% = -1 '{{Cl|DIM}} array first use | ||
Line 122: | Line 146: | ||
{{Cl|CLOSE}} #ff% | {{Cl|CLOSE}} #ff% | ||
{{Cl|KILL}} TmpFile$ | {{Cl|KILL}} TmpFile$ | ||
{{Cl|ELSE}} {{Cl|IF...THEN|IF}} Index% > 0 {{Cl|THEN}} Index% = Index% - 1 'no spec sends next file name | {{Cl|ELSE}} | ||
{{Cl|IF...THEN|IF}} Index% > 0 {{Cl|THEN}} Index% = Index% - 1 'no spec sends next file name | |||
{{Cl|END IF}} | {{Cl|END IF}} | ||
DIR$ = DirList$(Index%) | DIR$ = DirList$(Index%) | ||
{{Cl|END FUNCTION}} | {{Cl|END FUNCTION}} | ||
{{CodeEnd}} {{ | {{CodeEnd}} | ||
{{Small|Code by Ted Weissgerber}} | |||
{{PreStart}} | |||
'''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%''. | |||
{{PreEnd}} | |||
<p style="text-align: center">([[#top|Return to Table of Contents]])</p> | |||
{{ | {{PageReferences}} |
Latest revision as of 13:21, 19 November 2024
QB64 was created to be compatible with QB 4.5 or lower versions. PDS(7.1) is not supported. The following sub-procedures have been created to do things that were available in PDS versions of QuickBASIC 7.0 and 7.1.
CURRENCY
MKC$
- PDS could use the CURRENCY variable type and had the MKC$ function to convert those values into 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 '----------------------------------------------- 'converts currency amount to PDS currency string '----------------------------------------------- FUNCTION MKC$ (CurrVal AS _FLOAT) DIM CVal AS _INTEGER64 CVal = CurrVal * 10000 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.
- In this example the procedure gets the currency string from a file.
SCREEN 12 DIM currency AS STRING * 8 OPEN "currency.bin" FOR BINARY AS #1 'binary file with MKC$ values created by PDS GET #1, , currency CLOSE #1 _PRINTSTRING (1, 10), "[" + currency + "]" 'show ASCII string value from file _PRINTSTRING (1, 30), STR$(CVC##(currency)) END '----------------------------------------------------------- 'converts currency string to a _FLOAT currency amount '----------------------------------------------------------- FUNCTION CVC## (CurrStr AS STRING) DIM CV AS _INTEGER64 CV = _CV(_INTEGER64, CurrStr) CVC## = CV / 10000 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.
- Remember to multiply the currency value by 10000 before putting to file.
- Currency values can be PUT directly into BINARY or RANDOM files using an _INTEGER64 variable value.
DIM curr AS _INTEGER64, currency AS _FLOAT currency = 9876.543 curr = currency * 10000 'multiply currency value OPEN "currency.bin" FOR 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.
- Remember to divide the currency value by 10000 after getting from file.
- When currency values are PUT directly into a BINARY or RANDOM file, _INTEGER64 can GET them directly.
DIM curr AS _INTEGER64, currency AS _FLOAT OPEN "currency.bin" FOR BINARY AS #1 'any binary file holding PDS currency values GET #1, , curr CLOSE #1 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.
DIR$
- Attention
- 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 specification (spec$) can use a path and/or wildcards.
FOR i = 1 TO 2 PRINT LINE INPUT "Enter a file spec: ", spec$ file$ = DIR$(spec$) 'use a file spec ONCE to find the last file name listed PRINT DIRCount%, file$, 'function can return the file count using SHARED variable IF DIRCount% > 1 THEN DO K$ = INPUT$(1) file$ = DIR$("") 'use an empty string parameter to return a list of files! PRINT file$, LOOP UNTIL LEN(file$) = 0 'file list ends with an empty string END IF NEXT END FUNCTION DIR$ (spec$) CONST TmpFile$ = "DIR$INF0.INF", ListMAX% = 500 'change maximum to suit your needs SHARED DIRCount% 'returns file count if desired. STATIC Ready%, Index%, DirList$() IF NOT Ready% THEN REDIM DirList$(ListMAX%): Ready% = -1 'DIM array first use IF 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 APPEND AS #ff% size& = LOF(ff%) CLOSE #ff% IF size& = 0 THEN KILL TmpFile$: EXIT FUNCTION OPEN TmpFile$ FOR INPUT AS #ff% DO WHILE NOT EOF(ff%) AND Index% < ListMAX% Index% = Index% + 1 LINE INPUT #ff%, DirList$(Index%) LOOP DIRCount% = Index% 'SHARED variable can return the file count CLOSE #ff% KILL TmpFile$ ELSE IF Index% > 0 THEN Index% = Index% - 1 'no spec sends next file name END IF DIR$ = DirList$(Index%) END FUNCTION |
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%. |