Q(uick)BASIC Function: MKDMBF$
Quick View
MKDMBF$
A conversion function that converts an IEEE-format number to a string containing a Microsoft Binary format number
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- MKSMBF$(single-precision-expression!)
- MKDMBF$(double-precision-expression#)
- CVSMBF (4-byte-numeric-string)
- CVDMBF (8-byte-numeric-string)
Description/Parameter(s)
MKSMBF$ and MKDMBF$ convert IEEE-format numbers to Microsoft-Binary-format numeric strings that can be stored in FIELD statement string variables. CVSMBF and CVDMBF convert those strings back to IEEE-format numbers.
Function | Returns |
MKSMBF$ | A 4-byte string containing a Microsoft-Binary-format number |
MKDMBF$ | An 8-byte string containing a Microsoft-Binary-format number |
CVSMBF | A single-precision number in IEEE format |
CVDMBF | A double-precision number in IEEE format |
- These functions are useful for maintaining data files created with older versions of Basic.
Example
TYPE Buffer
SngNum AS STRING * 4
DblNum AS STRING * 8
END TYPE
DIM RecBuffer AS Buffer
OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN = 12
SNum = 98.9
DNum = 645.3235622#
RecBuffer.SngNum = MKSMBF$(SNum)
RecBuffer.DblNum = MKDMBF$(DNum)
PUT #1, 1, RecBuffer
GET #1, 1, RecBuffer
CLOSE #1
PRINT CVSMBF(RecBuffer.SngNum), CVDMBF(RecBuffer.DblNum)
See also:
Syntax
- MKSMBF$(single-precision-expression)
- MKDMBF$(double-precision-expression)
Description/Parameter(s)
These functions are used to write real numbers to random-access files using Microsoft Binary format. They are particularly useful for maintaining data files created with older versions of BASIC.
The MKSMBF$ and MKDMBF$ functions convert real numbers in IEEE-format to strings so they can be written to the random-access file.
To write a real number to a random-access file in Microsoft Binary format, convert the number to a string using MKSMBF$ (for a single-precision number) or MKDMBF$ (for a double-precision number). Then store the result in the corresponding field (defined in the FIELD statement) and write the record to the file using the PUT statement.
Example
The following example uses MKSMBF$ to store real values in a file as Microsoft Binary format numbers:
' Read a name and a test score from the console.
' Store as a record in a random-access file.
' Scores are written out as
' Microsoft Binary format single-precision values.
TYPE Buffer
NameField AS STRING * 20
ScoreField AS STRING * 4
END TYPE
DIM RecBuffer AS Buffer
OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN=LEN(RecBuffer)
'
PRINT "Enter a name and a score, separated by a comma."
PRINT "Enter 'END, 0' to end input."
INPUT NameIn$, Score
'
I=0
' Read pairs of names and scores from the console
' until the name is END.
DO WHILE UCASE$(NameIn$) <> "END"
I=I+1
RecBuffer.NameField=NameIn$
'
' Convert the score to a string.
RecBuffer.ScoreField=MKSMBF$(Score)
PUT #1,I,RecBuffer
INPUT NameIn$, Score
LOOP
'
PRINT I;" records written."
CLOSE #1
Syntax
- MKSMBF$(single-precision-expression!)
- MKDMBF$(double-precision-expression#)
Description/Parameter(s)
Usage Notes
- These functions are used to write real numbers to random-access files using Microsoft-Binary format. They are particularly useful for maintaining data files created with older versions of BASIC.
- The MKSMBF$ and MKDMBF$ functions convert real numbers in IEEE format to strings containing MBF numbers so they can be written to the random-access file.
- To write a real number to a random-access file in Microsoft-Binary format, convert the number to a string using MKSMBF$ (for a single-precision number) or MKDMBF$ (for a double-precision number). Then store the result in the corresponding field (defined in the FIELD statement) and write the record to the file using the PUT statement.
- Currency numbers are not real numbers, so they cannot be converted to strings that contain Microsoft-Binary-format numbers.
Example
This example uses the MKSMBF$ function to store real values in a file as Microsoft-Binary-format numbers.
'Read a name and a test score from the console.
'Store as a record in a random-access file.
'Scores are written out as
'Microsoft-Binary-format single-precision values.
TYPE Buffer
NameField AS STRING * 20
ScoreField AS STRING * 4
END TYPE
DIM RecBuffer AS Buffer
OPEN "TESTDAT.DAT" FOR RANDOM AS #1 LEN = LEN(RecBuffer)
PRINT "Enter a name and a score, separated by a comma."
PRINT "Enter 'END, 0' to end input."
INPUT NameIn$, Score
I = 0
'Read pairs of names and scores from the console
'until the name is END.
DO WHILE UCASE$(NameIn$) <> "END"
I = I + 1
RecBuffer.NameField = NameIn$
'Convert the score to a string.
RecBuffer.ScoreField = MKSMBF$(Score)
PUT #1, I, RecBuffer
INPUT NameIn$, Score
LOOP
PRINT I; " records written."
CLOSE #1