CAST function

Purpose:

CAST converts a variable from one data type to another.

Syntax:

NewObject = CAST(DataType, Object)

Return Value:

  • NewObject The Object cast to a different data type.

Parameters:

  • DataType the data type to which the object is to be cast.
  • Object the object whose data type is to be cast to a different data type.

Example:

UNION MyUnion
  MyInt  AS DOUBLE
  MyChar AS UCHAR
END UNION

DIM Example AS MyUnion
DIM longvar AS LONG

Example.MyChar = 255

'longvar = (LONG) Example            ' This statement will -NOT- compile with any compiler. 

longvar = (LONG) Example.MyChar      ' This statement WILL compile with any C/C++ compiler. 
longvar = CAST(LONG, Example.MyChar) ' This statement WILL also compile, using the CAST macro. 

PRINT longvar                        ' Should PRINT 255 

PAUSE

MKD$ function

Purpose:

MKD$ converts a DOUBLE precision number to an 8-byte fixed length string.

Syntax:

Retstr = MKD$(DoubleNum AS DOUBLE)

Return Value:

  • Data type: STRING
    Retstr An 8-byte fixed length string.

Parameters:

  • Data type: DOUBLE
    DoubleNum Number to be converted to an 8-byte fixed length string.

Remarks:

πŸ‘‰ The returned string is stored in binary form which can include embedded zeros. Most BCX string functions and operators cannot handle these strings because zero, normally, is used as a terminator to indicate the end of the string.

A MKD$ function call should not be used as the return value to a string function.

'WRONG:
FUNCTION foo$ ()
 LOCAL D AS DOUBLE
 D# = 555555.5555
 FUNCTION = MKD$(D#)
END FUNCTION

'CORRECT:
FUNCTION foo () AS LPSTR
 LOCAL R$
 LOCAL D AS DOUBLE
 D# = 555555.5555
 R$ = MKD$(D#)
 FUNCTION = R
END FUNCTION

Also note that only single assignments should be performed.

A$ = MKD$(dbl#)           ' Valid
A$ = MKD$(dbl#) + "string" ' Not Valid

These limitations are due to the fact that these functions contain binary data. Also, be careful not to reassign a string:

B$ = A$

would not give the desired result since it would use strcpy.

MKLD$ function

Purpose:

MKLD$ converts an LDOUBLE precision number to an 10-byte fixed length string.

Syntax:

Retstr = MKLD$(LongDoubleNum AS LDOUBLE)

Return Value:

  • Data type: STRING
    Retstr A 10-byte fixed length string.

Parameters:

  • Data type: LDOUBLE
    LongDoubleNum Number to be converted to an 10-byte fixed length string.

Remarks:

πŸ‘‰ The returned string is stored in binary form which can include embedded zeros. Most BCX string functions and operators cannot handle these strings because zero, normally, is used as a terminator to indicate the end of the string.

A MKLD$ function call should not be used as the return value to a string function.

'WRONG:
FUNCTION foo$ ()
 LOCAL D AS LDOUBLE
 D = 555555.5555
 FUNCTION = MKLD$(D#)
END FUNCTION

'CORRECT:
FUNCTION foo () AS LPSTR
 LOCAL R$
 LOCAL D AS LDOUBLE
 D = 555555.5555
 R$ = MKLD$(D#)
 FUNCTION = R
END FUNCTION

Also note that only single assignments should be performed.

A$ = MKLD$(LongDoubleNum)           ' Valid
A$ = MKLD$(LongDoubleNum) + "string" ' Not Valid

These limitations are due to the fact that these functions contain binary data. Also, be careful not to reassign a string:

B$ = A$

would not give the desired result since it would use strcpy.

MKI$ function

Purpose:

MKI$ converts a 16-bit (2-byte) SHORT to a 2-byte fixed length string.

Syntax:

Retstr = MKI$(ShortNum AS SHORT)

Return Value:

  • Data type: STRING
    Retstr is an 2-byte fixed length string.

Parameters:

  • Data type: SHORT
    ShortNum Number to be converted to an 2-byte fixed length string.

Remarks:

πŸ‘‰ The returned string is stored in binary form which can include embedded zeros. Most BCX string functions and operators cannot handle these strings because zero, normally, is used as a terminator to indicate the end of the string.

A MKI$ function call should not be used as the return value to a string function.

'WRONG:
FUNCTION foo$ ()
 LOCAL D AS SHORT
 D = 5555
 FUNCTION = MKI$(D)
END FUNCTION

'CORRECT:
FUNCTION foo () AS LPSTR
 LOCAL R$
 LOCAL D AS SHORT
 D = 5555
 R$ = MKI$(D)
 FUNCTION = R
END FUNCTION

Also note that only single assignments should be performed.

A$ = MKI$(ShortNum)           ' Valid
A$ = MKI$(ShortNum) + "string" ' Not Valid

These limitations are due to the fact that these functions contain binary data. Also, be careful not to reassign a string:

B$ = A$

would not give the desired result since it would use strcpy.

MKL$ function

Purpose:

MKL$ converts an INTEGER to an 4-byte fixed length string.

Syntax:

Retstr = MKL$(IntNum AS INTEGER)

Return Value:

  • Data type: STRING
    Retstr , the return value, is an 4-byte fixed length string.

Parameters:

  • Data type: INTEGER
    IntNum Number to be converted to an 4-byte fixed length string.

Remarks:

πŸ‘‰ The returned string is stored in binary form which can include embedded zeros. Most BCX string functions and operators cannot handle these strings because zero, normally, is used as a terminator to indicate the end of the string.

A MKL$ function call should not be used as the return value to a string function.

'WRONG:
FUNCTION foo$ ()
 LOCAL D%
 D% = 555555
 FUNCTION = MKL$(D%)
END FUNCTION

'CORRECT:
FUNCTION foo () AS LPSTR
 LOCAL R$
 LOCAL D%
 D% = 555555
 R$ = MKL$(D%)
 FUNCTION = R
END FUNCTION

Also note that only single assignments should be performed.

A$ = MKL$(IntNum)           ' Valid
A$ = MKL$(IntNum) + "string" ' Not Valid

These limitations are due to the fact that these functions contain binary data. Also, be careful not to reassign a string:

B$ = A$

would not give the desired result since it would use strcpy.

MKS$ function

Purpose:

MKS$ converts a SINGLE precision number to an 4-byte fixed length string.

Syntax:

Retstr = MKS$(Single AS SINGLE)

Return Value:

  • Data type: STRING
    Retstr A 4-byte fixed length string.

Parameters:

  • Data type: SINGLE
    Single Number to be converted to a 4-byte fixed length string.

Remarks:

πŸ‘‰ The returned string is stored in binary form which can include embedded zeros. Most BCX string functions and operators cannot handle these strings because zero, normally, is used as a terminator to indicate the end of the string.

A MKS$ function call should not be used as the return value to a string function.

'WRONG:
FUNCTION foo$ ()
 LOCAL D AS SINGLE
 D! = 55.5555
 FUNCTION = MKS$(D!)
END FUNCTION
 
'CORRECT:
FUNCTION foo () AS LPSTR
 LOCAL R$
 LOCAL D AS SINGLE
 D! = 55.5555
 R$ = MKS$(D!)
 FUNCTION = R
END FUNCTION

Also note that only single assignments should be performed.

A$ = MKS$(FloatNum!)           ' Valid
A$ = MKS$(FloatNum!) + "string" ' Not Valid

These limitations are due to the fact that these functions contain binary data. Also, be careful not to reassign a string:

B$ = A$

would not give the desired result since it would use strcpy.

CVD function

Purpose:

CVD converts a MKD$ format 8-byte fixed length string to a DOUBLE precision number.

Syntax:

Retval = CVD(MKDString AS STRING)

Return Value:

  • Data type: DOUBLE
    Retval A double precision number.

Parameters:

  • Data type: STRING
    MKDString An MKD format 8-byte fixed length string to be converted to a DOUBLE precision number.

CVLD function

Purpose:

CVLD converts a MKLD$ format 10-byte fixed length string to an LDOUBLE precision number.

Syntax:

Retval = CVLD(MKLDString AS STRING)

Return Value:

  • Data type: LDOUBLE
    Retval A ldouble precision number.

Parameters:

  • Data type: STRING
    MKLDString An MKLD format 10-byte fixed length string to be converted to an LDOUBLE precision number.

CVI function

Purpose:

CVI converts an MKI$ format 2-byte fixed length string to a 16-bit(2-byte) SHORT number.

Syntax:

Retval = CVI(MKIString AS STRING)

Return Value:

Parameters:

  • Data type: STRING
    MKIString An MKI format 2-byte fixed length string to be converted to 16-bit(2-byte) SHORT number.

CVL function

Purpose:

CVL converts an MKL$ format 4-byte fixed length string to a LONG integer number.

Syntax:

Retval = CVL(MKLString AS STRING)

Return Value:

  • Data type: LONG
    Retval A 32-bit(4-byte) number.

Parameters:

  • Data type: STRING
    MKLString An MKL format 4-byte fixed length string to be converted to a 32-bit(4-byte) LONG number.

CVS function

Purpose:

CVS converts an MKS$ format 4-byte fixed length string to a SINGLE precision number.

Syntax:

Retval = CVS(MKSString AS STRING)

Return Value:

  • Data type: SINGLE
    Retval A single precision number.

Parameters:

  • Data type: STRING
    MKSString An MKS format 4-byte fixed length string to be converted to a SINGLE precision number.

Example:

DIM int1%
DIM str1$
DIM str2$
DIM sng1!
DIM sng2!
DIM dbl1#
DIM dbl2#

str1$ = "AB"
int1% = CVI(str1$)
PRINT int1%
str2$ = MKI$(int1%)
PRINT str2$

str1$ = "ABCD"
int1% = CVL(str1$)
PRINT int1%
str2$ = MKL$(int1%)
PRINT str2$

sng1! = 1.23456
str1$ = MKS$(sng1!)
PRINT str1$
sng2! = CVS(str1$)
PRINT sng2!

dbl1# = 1.23456789012345
str1$ = MKD$(dbl1#)
PRINT str1$
dbl2# = CVD(str1$)
PRINT dbl2#

Result:

 16961
 AB
 1145258561
 ABCD
 ΕΎ?
 1.23456
 ÝYΕ’BΓŠΓ€Γ³?
 1.23456789012345