Difference between revisions of "VB Procedures"

From QB64 Wiki
Jump to navigation Jump to search
m (Fix example highlighting/linking)
 
Line 1: Line 1:
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 Visual Basic:
QB64 was 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 Visual Basic.


==CURRENCY==
==CURRENCY==
Line 14: Line 14:


{{Cl|FUNCTION}} MKC$ (CurrVal {{Cl|AS}} {{Cl|_FLOAT}}) 'converts currency amount to currency string
{{Cl|FUNCTION}} MKC$ (CurrVal {{Cl|AS}} {{Cl|_FLOAT}}) 'converts currency amount to currency string
{{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}}
Line 26: Line 26:
{{Cl|SCREEN}} 12
{{Cl|SCREEN}} 12
{{Cl|DIM}} currency {{Cl|AS}} {{Cl|STRING}} * 8
{{Cl|DIM}} currency {{Cl|AS}} {{Cl|STRING}} * 8
{{Cl|OPEN}} "Currency.bin" {{Cl|FOR...NEXT|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 'binary file with MKC$ values created by PDS or VB
{{Cl|OPEN}} "Currency.bin" {{Cl|FOR (file statement)|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 'binary file with MKC$ values created by PDS or VB
{{Cl|GET}} #1, , currency
{{Cl|GET}} #1, , currency
{{Cl|CLOSE}} #1
{{Cl|CLOSE}} #1
Line 37: Line 37:


{{Cl|FUNCTION}} CVC## (CurrStr {{Cl|AS}} {{Cl|STRING}}) 'converts currency string to currency amount
{{Cl|FUNCTION}} CVC## (CurrStr {{Cl|AS}} {{Cl|STRING}}) 'converts currency string to currency amount
{{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}}
Line 53: Line 53:
curr = currency * 10000 ' multiply currency value by 10000
curr = currency * 10000 ' multiply currency value by 10000


{{Cl|OPEN}} "currency.bin" {{Cl|FOR...NEXT|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 ' a binary file to hold VB currency values
{{Cl|OPEN}} "currency.bin" {{Cl|FOR (file statement)|FOR}} {{Cl|BINARY}} {{Cl|AS}} #1 ' a binary file to hold VB currency values
{{Cl|PUT}} #1, , curr
{{Cl|PUT}} #1, , curr
{{Cl|CLOSE}} #1
{{Cl|CLOSE}} #1
Line 65: Line 65:
{{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...NEXT|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 79: Line 79:
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p>
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p>


==References==


''See also:''
{{PageSeeAlso}}
* [[PDS (7.1) Procedures]]
* [[PDS (7.1) Procedures]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 07:27, 23 February 2021

QB64 was 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 Visual Basic.

CURRENCY

MKC$

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

SCREEN 12 value = 12345.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 currency string DIM CVal AS _INTEGER64 CVal = CurrVal * 10000 MKC = _MK$(_INTEGER64, CVal) END FUNCTION

The currency amount must be multiplied by 10000 before it is converted to the 8 byte ASCII string value.

CVC

VB also had the CVC function to convert MKC$ currency 8 byte string values back to currency amounts. QB64 can use _CV with _INTEGER64 to convert those values back to _FLOAT currency values:

SCREEN 12 DIM currency AS STRING * 8 OPEN "Currency.bin" FOR BINARY AS #1 'binary file with MKC$ values created by PDS or VB GET #1, , currency CLOSE #1 _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 currency amount DIM CV AS _INTEGER64 CV = _CV(_INTEGER64, CurrStr) CVC = CV / 10000 END FUNCTION

The 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.

DIM curr AS _INTEGER64, currency AS _FLOAT currency = 9876.543 curr = currency * 10000 ' multiply currency value by 10000 OPEN "currency.bin" FOR BINARY AS #1 ' a binary file to hold VB currency values PUT #1, , curr CLOSE #1 END

GET

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

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.

(Return to Table of Contents)


See also



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page