Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Code Block
Print 5.tostr()+"th"
Print "5".toint()+5
 
-5.tostr()    'This will cause an error. Instead, use the following:
(-5).tostr()
 
if type(5.tostr())<> "String" then stop
if (-5).tostr()<>"-5" then stop
if (1+2).tostr()<>"3" then stop
i=-55
if i.tostr()<>"-55" then stop
if 100%.tostr()<>"100" then stop
if (-100%).tostr()<>"-100" then stop
y%=10
if y%.tostr()<>"10" then stop
      
if "5".toint()<>5 or type("5".toint())<>"Integer" then stop
if "5".tofloat()<>5.0 or type("5".tofloat())<>"Float" then stop
fs="-1.1"
if fs.tofloat()<>-1.1 or fs.toint()<>-1 then stop
      
if "01234567".left(3)<>"012" then stop
if "01234567".right(4)<>"4567" then stop
if "01234567".mid(3)<>"34567" then stop
if "01234567".mid(3,1)<>"3" then stop
if "01234567".instr("56")<>5 then stop
if "01234567".instr(6,"56")<>-1 then stop
if "01234567".instr(0,"0")<>0 then stop

Interfaces

Interfaces in BrightScript operate similarly to Java or Microsoft COM: An interface is a known set of member functions that implement a set of logic. In some ways, an interface is similar to a virtual base class in C++; any script or program that is compatible with C can use an object interface without regards to the type of object it belongs to: For example, the roSerialPort object, which controls the standard serial interface (RS-232), implements three interfaces: ifSerialControl, ifStreamReceive, and ifStreamSend. Since the print statement sends its output to any object that has an ifStreamSend interface, it works with the roSerialPort object, as well as any other object with the ifStreamSend interface.

Statement and Interface Integration

Some BrightScript statements have integrated functionality with interfaces. This section describes how to use statements with interfaces.

PRINT

Using the PRINT statement in the following format will print into an object that has an ifStreamSend interface, including the roTextField and roSerialPort objects:

 

Code Block
print #object, "string"

 

If the expression being printed evaluates to an object with an ifEnum interface, the PRINT statement will print every item that can be enumerated.

In addition to printing the values of intrinsic types, the PRINT statement can also be used to print any object that exposes one of the following interfaces: ifString, ifInt, ifFloat.

WAIT

The WAIT statement can work in conjunction with any object that has an ifMessagePort interface.

Expression Parsing

Any expression that expects a certain type of variable—including Integer, Float, Double, Boolean, or String—can accept an object with an interface equivalent of that type: ifInt, ifFloat, ifDouble, ifBoolean, ifString.

Array Operator

The [ ] array operator works with any object that has an ifArray or ifAssociativeArray interface, including arrays, associative arrays, and lists.

Member Access Operator

The member access operator (i.e. Dot Operator) works with any object that has an ifAssociativeArray interface. It also works with any object when used to call a member function (i.e. method). It also has special meaning when used on an roXMLElement or roXMLList object.