Difference between revisions of "VB procedures"

From QB64 Wiki
Jump to navigation Jump to search
(Redirected page to VB Procedures)
(3 intermediate revisions by one other user not shown)
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:
#REDIRECT [[VB Procedures]]
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:
{{Cl|SCREEN}} 12
value = 12345.6789 '    any currency value with up to 4 decimal point places
{{Cl|_PRINTSTRING}} (1, 50), "[" + MKC$(value) + "]" ' show ASCII string value
{{Cl|FUNCTION}} MKC$ (CurrVal {{Cl|AS}} {{Cl|_FLOAT}}) 'converts currency amount to currency string
{{Cl|DIM}} CVal {{Cl|AS}} {{Cl|_INTEGER64}}
CVal = CurrVal * 10000
MKC = {{Cl|_MK$}}({{Cl|_INTEGER64}}, CVal)
{{Cl|END FUNCTION}} '' ''
: The currency amount must be multiplied by 10000 before it is converted to the [[ASCII]] string value.
VB also had the CVC function to convert MKC$ currency string values back to currency amounts. QB64 can use [[_CV]] with [[_INTEGER64]] to convert those values back to [[_FLOAT]] currency values:
{{CodeStart}} '' ''
{{Cl|SCREEN}} 12
{{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|GET}} #1, , currency
{{Cl|CLOSE}} #1
{{Cl|_PRINTSTRING}} (1, 10), "[" + currency + "]" 'show ASCII string value from file
{{Cl|_PRINTSTRING}} (1, 30), {{Cl|STR$}}(CVC##(currency))
{{Cl|FUNCTION}} CVC## (CurrStr {{Cl|AS}} {{Cl|STRING}}) 'converts currency string to currency amount
{{Cl|DIM}} CV {{Cl|AS}} {{Cl|_INTEGER64}}
CV = {{Cl|_CV}}({{Cl|_INTEGER64}}, CurrStr)
CVC = CV / 10000
{{Cl|END FUNCTION}} '' ''
: The currency amount must be divided by 10000 to create the 4 decimal point places.
{{CodeStart}} '' ''
{{Cl|DIM}} textval {{Cl|AS}} {{Cl|STRING}} * 10
textval = {{Cl|STR$}}(123567)
txt$ = TRIM$(textval$)
{{Cl|PRINT}} "[" + txt$ + "]"
{{Cl|FUNCTION}} TRIM$(text {{Cl|AS}} {{Cl|STRING}})
text$ = {{Cl|LTRIM$}}({{Cl|RTRIM$}}(text$))
TRIM$ = text$
{{Cl|END FUNCTION}} '' ''

Latest revision as of 22:54, 20 August 2017

Redirect to: