Conversions: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
'''Function'''
== Function ==


CBOOL(''expression'')
CBool(''expression'')


CBYTE(''expression'')
CByte(''expression'')


CCUR(''expression'')
CCur(''expression'')


CDATE(''expression'')
CDate(''expression'')


CDBL(''expression'')
CDbl(''expression'')


CINT(''expression'')
CInt(''expression'')


CLNG(''expression'')
CLng(''expression'')


CSNG(''expression'')
CSng(''expression'')


CSTR(''expression'')
CStr(''expression'')


'''Description'''
== Description ==


The conversion functions return an expression that has been converted to the appropriate type. The required parameter, ''expression'', is any valid expression.
The conversion functions return an expression that has been converted to the appropriate type. The required parameter, ''expression'', is any valid expression.
Line 31: Line 31:
! Function !! Returns !! Comments
! Function !! Returns !! Comments
|-
|-
| CBOOL || Boolean || False if expression is zero True otherwise
| CBool || Boolean || False if expression is zero True otherwise
|-
|-
| CBYTE || Byte || A whole number that ranges from 0 to 255
| CByte || Byte || A whole number that ranges from 0 to 255
|-
|-
| CCUR || Currency || A Currency Datum
| CCur || Currency || A Currency Datum
|-
|-
| CDATE || Date || Date range January 1, 100 to December 31, 9999,
| CDate || Date || Date range January 1, 100 to December 31, 9999,


Valid expressions are date expressions, or date/time literals
Valid expressions are date expressions, or date/time literals
|-
|-
| CDBL || Double || Number ranges from
| CDbl || Double || Number ranges from


-1.79769313486232E308 to
-1.79769313486232E308 to
Line 47: Line 47:
-4.94065645841247E-324 for negative values, and from 4.94065645841247E-324 to 1.79769313486232E308 for positive values
-4.94065645841247E-324 for negative values, and from 4.94065645841247E-324 to 1.79769313486232E308 for positive values
|-
|-
| CINT || Integer || Number ranges from -32,768 to 32,767, values with fractional parts (fp) are rounded
| CInt || Integer || Number ranges from -32,768 to 32,767, values with fractional parts (fp) are rounded


fp < 0.5 rounded down
fp < 0.5 rounded down
Line 55: Line 55:
fp = 0.5 rounded to nearest even number
fp = 0.5 rounded to nearest even number
|-
|-
| CLNG || Long Integer || Number ranges from
| CLng || Long Integer || Number ranges from


-2,147,483,648 to 2,147,483,647, values with fractional parts (fp) are rounded
-2,147,483,648 to 2,147,483,647, values with fractional parts (fp) are rounded
Line 65: Line 65:
fp = 0.5 rounded to nearest even number
fp = 0.5 rounded to nearest even number
|-
|-
| CSNG || Single || Number ranges from
| CSng || Single || Number ranges from


-3.403823E38 to
-3.403823E38 to
Line 73: Line 73:
1.401298E-45 to 3.403823E38 for positive numbers
1.401298E-45 to 3.403823E38 for positive numbers
|-
|-
| CSTR || String || •Booleans are converted to &quot;True&quot; or &quot;False&quot;
| CStr || String || •Booleans are converted to &quot;True&quot; or &quot;False&quot;


•Dates converted to short-date format of system
•Dates converted to short-date format of system
Line 82: Line 82:
|}
|}


'''Example'''
== Example ==
 
<pre>
<pre>
REM Conversion Functions Example
REM Conversion Functions Example
PRINT "CBYTE(99.44) = " & CBYTE(99.44)
PRINT "CByte(99.44) = " & CByte(99.44)
PRINT "CCUR(9283.066) = " & CCUR(9283.066)
PRINT "CCur(9283.066) = " & CCur(9283.066)
PRINT "CDATE(8/18/98) = " & CDATE("8/18/98")
PRINT "CDate(8/18/98) = " & CDate("8/18/98")
PRINT "CDBL(3.141593) = " & CDBL("3.141593")
PRINT "CDbl(3.141593) = " & CDbl("3.141593")
PRINT "CINT(3.141593) = " & CINT("3.141593")
PRINT "CInt(3.141593) = " & CInt("3.141593")
PRINT "CSNG(10) = " & CSNG(10)
PRINT "CSng(10) = " & CSng(10)
PRINT "CSTR(TRUE) = " & CSTR(TRUE)
PRINT "CStr(TRUE) = " & CStr(TRUE)
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
CBYTE(99.44) = 99
CByte(99.44) = 99
CCUR(9283.066) = 9283.066
CCur(9283.066) = 9283.066
CDATE(8/18/98) = 8/18/1998
CDate(8/18/98) = 8/18/1998
CDBL(3.141593) = 3.141593
CDbl(3.141593) = 3.141593
CINT(3.141593) = 3
CInt(3.141593) = 3
CSNG(10) = 10
CSng(10) = 10
CSTR(TRUE) = True
CStr(TRUE) = True
</pre>
</pre>


'''Related Items''''
== Related Items ==


[[is functions|IS FUNCTION]]
[[is functions|IS FUNCTION]]
[[Category:Language Reference]]

Revision as of 20:29, 8 August 2012

Function

CBool(expression)

CByte(expression)

CCur(expression)

CDate(expression)

CDbl(expression)

CInt(expression)

CLng(expression)

CSng(expression)

CStr(expression)

Description

The conversion functions return an expression that has been converted to the appropriate type. The required parameter, expression, is any valid expression.

If the return value lies outside the acceptable range of its return type, an error occurs.

Table 5: Conversion Functions

Function Returns Comments
CBool Boolean False if expression is zero True otherwise
CByte Byte A whole number that ranges from 0 to 255
CCur Currency A Currency Datum
CDate Date Date range January 1, 100 to December 31, 9999,

Valid expressions are date expressions, or date/time literals

CDbl Double Number ranges from

-1.79769313486232E308 to

-4.94065645841247E-324 for negative values, and from 4.94065645841247E-324 to 1.79769313486232E308 for positive values

CInt Integer Number ranges from -32,768 to 32,767, values with fractional parts (fp) are rounded

fp < 0.5 rounded down

fp > 0.5 rounded up

fp = 0.5 rounded to nearest even number

CLng Long Integer Number ranges from

-2,147,483,648 to 2,147,483,647, values with fractional parts (fp) are rounded

fp < 0.5 rounded down

fp > 0.5 rounded up

fp = 0.5 rounded to nearest even number

CSng Single Number ranges from

-3.403823E38 to

-1.401298E-45 for negative numbers, and from

1.401298E-45 to 3.403823E38 for positive numbers

CStr String •Booleans are converted to "True" or "False"

•Dates converted to short-date format of system

•Errors converted to "Error <number>"

•Numbers converted to string containing the number

Example

REM Conversion Functions Example
PRINT "CByte(99.44) = " & CByte(99.44)
PRINT "CCur(9283.066) = " & CCur(9283.066)
PRINT "CDate(8/18/98) = " & CDate("8/18/98")
PRINT "CDbl(3.141593) = " & CDbl("3.141593")
PRINT "CInt(3.141593) = " & CInt("3.141593")
PRINT "CSng(10) = " & CSng(10)
PRINT "CStr(TRUE) = " & CStr(TRUE)

Output

CByte(99.44) = 99
CCur(9283.066) = 9283.066
CDate(8/18/98) = 8/18/1998
CDbl(3.141593) = 3.141593
CInt(3.141593) = 3
CSng(10) = 10
CStr(TRUE) = True

Related Items

IS FUNCTION