<div class="meta" robots="noindex">

</div>

Class

# RBScript

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated.. Please use `XojoScript</api/language/xojo_script/xojoscript>` as a replacement.

</div>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to dynamically execute code within a running (compiled) application.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                        | Type                                              | Read-Only | Shared |
|-----------------------------|---------------------------------------------------|-----------|--------|
| `Context<rbscript.context>` | `Object</api/data_types/additional_types/object>` |           |        |
| `Source<rbscript.source>`   | `String</api/data_types/string>`                  |           |        |
| `State<rbscript.state>`     | `Integer</api/data_types/integer>`                |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                              | Parameters                                              | Returns | Shared |
|-----------------------------------|---------------------------------------------------------|---------|--------|
| `Precompile<rbscript.precompile>` | optimizationLevel As `Integer</api/data_types/integer>` |         |        |
| `Reset<rbscript.reset>`           |                                                         |         |        |
| `Run<rbscript.run>`               |                                                         |         |        |

## Events

<div class="rst-class">

table-centered_column_4

</div>

| Name                                    | Parameters                                                                                                                                  | Returns                          |
|-----------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
| `CompilerError<rbscript.compilererror>` | line As `Integer</api/data_types/integer>`, errorNumber As `Integer</api/data_types/integer>`, errorMsg As `String</api/data_types/string>` |                                  |
| `Input<rbscript.input>`                 | prompt As `String</api/data_types/string>`                                                                                                  | `String</api/data_types/string>` |
| `Print<rbscript.print>`                 | msg As `String</api/data_types/string>`                                                                                                     |                                  |
| `RuntimeError<rbscript.runtimeerror>`   | line As `Integer</api/data_types/integer>`, error As `RuntimeException</api/exceptions/runtimeexception>`                                   |                                  |

## Constants

The following class constants can be used to specify the value of the State property.

| Class Constant  | Description                                           |
|-----------------|-------------------------------------------------------|
| kStateReady     | The script compiler is ready.                         |
| kStateRunning   | The script compiler is running.                       |
| kStateCompleted | The script compiler has completed running the script. |
| kStateAborted   | The script compiler has aborted.                      |

The following class constants can optionally be passed into Compile(). The default is kOptimizationLevelHigh. Run() does not take a level and defaults to kOptimizationLevelNone unless the script has already been compiled.

| Class Constant         | Description                                                                        |
|------------------------|------------------------------------------------------------------------------------|
| kOptimizationLevelNone | No optimizations will be performed and the script will be compiled lazily (a JIT). |
| kOptimizationLevelLow  | The script will be compiled up front, but few optimizations will be applied.       |
| kOptimizationLevelHigh | The script will be compiled up front and all possible optimizations should be ran. |

## Property descriptions

<div id="rbscript.context">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.Context

**Context** As `Object</api/data_types/additional_types/object>`

The object (e.g., window or class) that is made available to the <span class="title-ref">RBScript</span>.

You cannot pass any objects between the context and the script. This includes, for example, variants and arrays. Any methods or properties that use objects will not be allowed within the script.

For example, you can create a custom class and assign it to the Context property. The script would then have access to the methods and properties of this class. The methods become global methods and the properties become global properties.

<div id="rbscript.source">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.Source

**Source** As `String</api/data_types/string>`

The source code the compiler will run.

<div id="rbscript.state">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.State

**State** As `Integer</api/data_types/integer>`

The state of the script compiler.

State can take on the following class constants:

| Description     |
|-----------------|
| kStateReady     |
| kStateRunning   |
| kStateCompleted |
| kStateAborted   |

## Method descriptions

<div id="rbscript.precompile">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.Precompile

**Precompile**(optimizationLevel As `Integer</api/data_types/integer>`)

Runs the parser immediately instead of waiting until the next call to Run. Specify the optimizationLevel using the class constants.

<div id="rbscript.reset">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.Reset

**Reset**

Rewinds the compiler to start over from the beginning.

In this example, script is the <span class="title-ref">RBScript</span> that executes.

``` xojo
script.Reset
```

<div id="rbscript.run">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.Run

**Run**

Runs the code *Source* until it is done.

## Event descriptions

<div id="rbscript.compilererror">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.CompilerError

**CompilerError**(line As `Integer</api/data_types/integer>`, errorNumber As `Integer</api/data_types/integer>`, errorMsg As `String</api/data_types/string>`)

This event gets called if the script could not be compiled due to a syntax error in the code.

*line* is a one-based line number at which the error *may* be found. Do not rely on this, though - the error sometimes is found in the succeeding line.

You can look up the meaning of *errorNumber* in the <span class="title-ref">RBScript</span>.

The *errorMsg* parameter always returns "Error found while compiling" regardless of the error number.

<div id="rbscript.input">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.Input

**Input**(prompt As `String</api/data_types/string>`) As `String</api/data_types/string>`

The script requests input from the end user. Returns a `String</api/data_types/string>`. Used to get input from the user.

<div id="rbscript.print">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.Print

**Print**(msg As `String</api/data_types/string>`)

The compiler is returning the results of the script in *msg*. Used to display the passed string via a `MessageDialog</api/user_interface/desktop/messagedialog>` box.

<div id="rbscript.runtimeerror">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RBScript.RuntimeError

**RuntimeError**(line As `Integer</api/data_types/integer>`, error As `RuntimeException</api/exceptions/runtimeexception>`)

A runtime error, *error* has occurred.

## Notes

The <span class="title-ref">RBScript</span> language is an implementation of the Xojo programming language that allows end users to write and execute their own code within a compiled application. Scripts are compiled into machine language, rather then being interpreted.

Since <span class="title-ref">RBScript</span> is a class, you use it by creating an instance of this class either via code or by adding an <span class="title-ref">RBScript</span> control to a window. The easiest way to use <span class="title-ref">RBScript</span> is to assign the code to the Source property of the <span class="title-ref">RBScript</span> object and call the Run method.

To provide information to an <span class="title-ref">RBScript</span> while it's running, use the Input function. This function calls the Input event of the <span class="title-ref">RBScript</span> object where you can return the information you wish returned by the Input function in your <span class="title-ref">RBScript</span> code. In the following example, the results of the Input function are assigned to a variable:

``` xojo
Dim years, days As Integer
years = Val(Input("")) ' Prompt the user to enter a value
days = years * 365
```

The Input function takes a `String</api/data_types/string>` that can be used to provide a prompt in case you are going to provide a dialog box in which the user enters the information. Since the Input function returns a `String</api/data_types/string>` and we want to store the value as an integer, the `Val</api/text/val>` function is used to convert the string to an integer. In this case, if the number of years is going to be entered into a `TextField</api/deprecated/textfield>` called TextField1, then the Input event of the <span class="title-ref">RBScript</span> object would look like this:

``` xojo
Function Input(prompt As String) As String
  Return TextField1.Text
End Sub
```

When the Run method of the <span class="title-ref">RBScript</span> object is called, the code will be compiled and then executed. Since the Input function is called, the Input event of the <span class="title-ref">RBScript</span> object is executed and the contents of the Text property of the `TextField</api/deprecated/textfield>` is returned and assigned to the Years variable. Then the Days value is calculated.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Output information

The Print method is used to output data. This method takes a `String</api/data_types/string>` and passes it to the Print event of the <span class="title-ref">RBScript</span> object. Here is the example modified to use the Print function:

``` xojo
Dim years, days As Integer
years = Val(Input(""))
days = years * 365
Print(Str(days))
```

You access the value passed to the Print method through the Print event handler. For example, if you want to assign the value to the Text property of a `Label</api/deprecated/label>` object, the code for the Print event of the <span class="title-ref">RBScript</span> object would look like this:

``` xojo
Sub Print(msg As String)
Label1.Text = msg
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Handling errors in your code

If an error occurs while <span class="title-ref">RBScript</span> is compiling your code, the CompilerError event of the <span class="title-ref">RBScript</span> object will be called and will be passed appropriate error information so you can then decide how to handle the error. If the error occurs while the code is running, the RuntimeError event of the <span class="title-ref">RBScript</span> object is called and is passed appropriate error information. You can then decide how to respond to the error.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### More information

View these topics for more information about the scripting language, functions and errors:

- Scripting Language
- Scripting Functions
- Scripting Errors

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class;
