Creating a new Xbasic function
Observe as the instructor begins to build an Xbasic function to execute SQL calls.
- Make the “other” Control Panel active.
- Click the Code tab. Defining the function here will allow multiple Components to call it. (If we defined it under Xbasic Functions, or Server-side Events, it could only be called by the RevenuePieChart Component.)
- Click the button.
- From the menu that appears, choose Function. We define it as a Function because it returns a value. Script (using Xbasic editor) cannot return a value.
- The window appears. For the Function Name:, enter getDataForChart, and then click OK.
We are not defining any optional arguments for this function; we will define a required argument later.
- The Code Editor window appears, with some of the initial function definition already in place:
If you do not see line numbers in your Code Editor window:
- Right-click anywhere in the whitespace.
- From the menu that appears, choose Line numbers.
Now you create the getDataForChart function up to this point. Then:
- We need to pass the CustomerID of the selected customer to the function. Define an input parameter at the top of the function. Inside the parentheses of the function declaration on the first line, enter useThisCustomerID as C.
- Declare a variable that will use the input parameter as an argument to an SQL call later. After the function declaration, on a new line, enter the following (all on one line):
dim args as sql::Arguments ‘Use the SQL namespace Arguments structure as var type
:: indicates that the function should look to a particular server-side namespace.
- Assign the input parameter value to the argument variable. After the variable definition, on a new line 3, enter the following: args.Set("localWhatCustomerID",useThisCustomerID)
Note carefully that this argument is not the same one we defined for the Component earlier. This argument is local to the function.
When you finish, your function should look like this:
Along with the instructor, explore the features of the Code Editor.
- Review the choices available on the View, Task List, and Code menus at the top of the screen.
- Review the row of buttons along the top of the Code Editor window.
- Right-click in the window and review the menu that appears.
- Try the Indent/Outdent and Format Code options.