Q(uick)BASIC Function: CVSMBF

Quick View

CVSMBF

A conversion function that converts strings containing Microsoft Binary format numbers to IEEE-format numbers

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)
Syntax
  • CVSMBF (4-byte-string)
  • CVDMBF (8-byte-string)
Description/Parameter(s)

The CVSMBF and CVDMBF functions help you read old random-access files containing real numbers stored as strings in Microsoft Binary format. These functions convert the string read from the old file to an IEEE-format number:

Function Description
CVSMBF Converts a 4-byte-string containing a Microsoft Binary format number to a single-precision IEEE-format number.
CVDMBF Converts an 8-byte-string containing a Microsoft Binary format number to a double-precision IEEE-format number.
Example

The following program reads records from a random-access file containing Microsoft Binary format real numbers stored as strings. Each record contains a student's name and a test score.

' ' Define a user type for the data records. ' TYPE StudentRec NameField AS STRING * 20 Score AS STRING * 4 END TYPE ' Define a variable of the user type. DIM Rec AS StudentRec '******************************************************************** ' This part of the program is an insert whose only function is to ' create a random-access file to be used by the second part of the ' program, which demonstrates the CVSMBF function '******************************************************************** OPEN "TESTDAT1.DAT" FOR RANDOM AS #1 LEN = LEN(Rec) CLS RESTORE READ NameField$, Score$ I = 0 DO WHILE UCASE$(NameField$) <> "END" I = I + 1 Rec.NameField = NameField$ Rec.Score = Score$ PUT #1, I, Rec READ NameField$, Score$ IF NameField$ = "END" THEN EXIT DO LOOP CLOSE #1 ' DATA "John Simmons","100" DATA "Allie Simpson","95" DATA "Tom Tucker","72" DATA "Walt Wagner","90" DATA "Mel Zucker","92" DATA "END","0" '******************************************************************** ' This part of the program demonstrates the CVSMBF function '******************************************************************** ' Open the file for input. OPEN "TESTDAT1.DAT" FOR RANDOM AS #1 LEN=LEN(Rec) Max = LOF(1) / LEN(Rec) ' Read and print all of the records. FOR I = 1 TO Max ' Read a record into the user-type variable Rec. GET #1, I, Rec ' Convert the score from a string containing a Microsoft ' Binary format number to an IEEE-format number. ScoreOut = CVSMBF(Rec.Score) ' Display the name and score. PRINT Rec.NameField, ScoreOut NEXT I CLOSE #1 KILL "TESTDAT1.DAT" END
Syntax
  • CVSMBF (4-byte-string)
  • CVDMBF (8-byte-string)
Description/Parameter(s)

CVSMBF and CVDMBF return the IEEE-format equivalent of the Microsoft Binary format number contained in the string.

  • CVSMBF converts a 4-byte-string containing a Microsoft Binary format number to a single-precision IEEE-format number.
  • CVDMBF converts an 8-byte-string containing a Microsoft Binary format number to a double-precision IEEE-format number.

Usage Notes

  • These functions help you read old random-access files containing real numbers stored as strings in Microsoft Binary format.
Example

This example uses the CVSMBF function to convert Microsoft-Binary-format numbers stored as strings in a random-access file to IEEE-format numbers. Each record contains a student's name and a test score.

'Define a user type for the data records. TYPE StudentRec NameField AS STRING * 20 Score AS STRING * 4 END TYPE 'Define a variable of the user type. DIM Rec AS StudentRec 'Note: This part of the program is an insert whose function is to 'create a random-access file to be used by the second part of the 'program, which demonstrates the CVSMBF function. OPEN "TESTDAT1.DAT" FOR RANDOM AS #1 LEN = LEN(Rec) CLS RESTORE READ NameField$, S I = 0 DO WHILE UCASE$(NameField$) <> "END" I = I + 1 Rec.NameField = NameField$ LSET Rec.Score = MKSMBF$(S) PUT #1, I, Rec READ NameField$, S IF NameField$ = "END" THEN EXIT DO LOOP CLOSE #1 DATA "John Simmons",100 DATA "Allie Simpson",95 DATA "Tom Tucker",72 DATA "Walt Wagner",90 DATA "Mel Zucker",92 DATA "END",0 'This part of the program demonstrates the CVSMBF function. 'Open the file for input. OPEN "TESTDAT1.DAT" FOR RANDOM AS #1 LEN = LEN(Rec) Max = LOF(1) / LEN(Rec) 'Read and print all of the records. FOR I = 1 TO Max 'Read a record into the user-type variable Rec. GET #1, I, Rec 'Convert the score from a string containing a Microsoft- 'Binary-format number to an IEEE-format number. ScoreOut = CVSMBF(Rec.Score) 'Display the name and score. PRINT Rec.NameField, ScoreOut NEXT I CLOSE #1 KILL "TESTDAT1.DAT" END