VB procedures

From QB64 Wiki
Revision as of 19:16, 4 January 2012 by imported>Clippy (→‎CVC)
Jump to navigation Jump to search

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:



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 ASCII string value.


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 the 4 decimal point places.


DIM textval AS STRING * 10 textval = STR$(123567) txt$ = TRIM$(textval$) PRINT "[" + txt$ + "]" END FUNCTION TRIM$(text AS STRING) text$ = LTRIM$(RTRIM$(text$)) TRIM$ = text$ END FUNCTION


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