Xbasic GuideThe Interactive Window

The Xbasic Interactive Window executes code as you write it, letting you see the results of individual Xbasic commands immediately. The line-by-line interactive nature of the Interactive Window makes it easy to test Xbasic scripts and explore how an Xbasic command works. The Interactive Window is available everywhere you can add Xbasic, usually as a tab in the Xbasic editor.

Let's open the Interactive Window and become familiar with it by executing some simple Xbasic expressions. Click the "Interactive Window" toolbar button on the Web Projects Control Panel to open the Xbasic Interactive Window.

images/image001.png

Type the following in the Interactive Window and press enter:

? "Hello World"

You should see the following output in the Interactive Window:

="Hello World"

The ? operator prints the value of an expression in the Interactive Window. The Enter key executes the Xbasic on the line where the text cursor is located.

Try this: change the message from "Hello World" to your name. Then, while the mouse cursor is still on the same line as the ? statement, press enter. This executes the ? operator again and prints your name immediately after the statement.

images/image002.png

Select all of the text in the Interactive Window and delete it. Then, type the following in the Interactive Window and press Enter, replacing <Your name here> with your name.

name = "<Your name here>"

This line creates a character variable called name and assigns it the value of your name. We can verify this by typing the following command to display the value of name in the Interactive Window:

? name

You should see your name output in the Interactive Window.

When you create a variable in the Interactive Window, it is available until you close the Interactive Window or delete the variable using the DELETE statement (we discuss DELETE in a later section.) This means that you can continue to reference a variable even if you delete all of the code in the Interactive Window.

Enter the next line in the Interactive Window and run it:

today = now()

This line of code does two things. First, the now() function is called to get the current date and time. Then, a time variable called today is created and assigned the return value of the now() function.

You can use the typeof() function to determine the data type of a variable:

? typeof(today)

Executing this statement outputs T, which stands for "Time". T is the data type of the today variable. Other data types include character (C), numeric (N), and logical (L). We discuss data types in depth later in this guide.

Let's continue. Enter the following code on a new line and press enter:

dayOfWeek = time("Weekday", today)

The statement above creates a variable called dayOfWeek and sets the value of the variable to the weekday name. The weekday name is extracted from the today variable using the time() function.

The time() function converts a time value into a character string. It takes two parameters: a format string and a time value. The format string used here is Weekday. Weekday returns the full name of the weekday in proper case. There are other formatting options available. For example, run the following statement in the Interactive Window:

? time("Month d", today)

The statement prints the name of the month followed by the day of the month. Many formatting options exist for formatting date and time values. You can learn more about what format options are available in the Alpha Anywhere documentation for date and time variables. See Date and Time Format Elements to learn more.

Enter the following in the Interactive Window, executing each line as you write it:

message = "Hello " + name + "." + crlf() 
message = message + "Today is " + dayOfWeek + "."
? message

The + operator is used to concatenate multiple strings together into a single character string. The result is stored in the message variable. The second line adds the day of the week to the message. The crlf() function adds a newline to the message, breaking the text into two lines.

images/image003.png

There are other ways to inspect the value of a variable in the Interactive Window. One of them is using the showvar() function. showvar() displays a variable in a popup window. Let's display the message variable in a popup window. Type the code below into the Interactive Window and press Enter:

showvar(message,"Salutations")

This statement displays the message variable in a window with the title "Salutations":

images/image004.png

Interactive Window Commands

The Interactive Window has several commands for running and modifying code in the window. You are already familiar with two: executing the current line using the Enter key and printing the value of an expression using the ? operator.

  • Run Selected

    Multiple lines of code can be executed by highlighting multiple lines of code then right-clicking to open the context menu and selecting "Run Selected Code". Try it out: copy and paste the following code into the Interactive Window. Then select it, right-click anywhere in the whitespace of the Interactive Window, and select Run Selected Code.

    message = "This is a new message."+crlf()
    message = message + "It contains two lines."
    showvar(message,"Executing Multiple Lines")
    images/image005.png
  • Insert Newline

    Holding the Ctrl key while pressing Enter adds a new line to the Interactive Window without executing any statements. Inserting newlines without executing code is useful when writing multi-line statements, such as an IF statement, or in cases where you would like to insert a newline within existing statements.

    Place your mouse cursor at the beginning of the first line of the Interactive Window. Then press enter while holding down the Ctrl key.

    images/image006.png
  • Clear Screen

    Typing CLE and then pressing enter on a blank line deletes all text in the Interactive Window at and below the line containing the CLE command.

    Place the cursor on the first line of the Interactive Window. Then, type CLE and press Enter.

    images/image007.png
  • Deleting the text in the Interactive Window using the CLE command does not delete variables created during the Interactive Window session.

Now that you are familiar with the Interactive Window, let's start learning about the Xbasic Programming Language in the next section, Variables and Data Types.