Lesson 6. Variables and Expressions Lesson 5. Key ScreenSurfer HTML TagsLesson 7. Logic and control
 Click on any item to view...
Contents

+Introduction
+Concepts
+Product Positioning
+Operations
+Customization
+SurferScript Guide
ScreenSurfer Tutorial

The ScreenSurfer Tutorial Introduction

Visual Surfer Introduction

Lesson 1. The ScreenSurfer Environment

Lesson 2. 3270/5250 Display Characteristics

Lesson 3. SurferScript Screens and Events

Lesson 4. Basic Customization

Lesson 5. Key ScreenSurfer HTML Tags

Lesson 6. Variables and Expressions

Lesson 7. Logic and control

Lesson 8. Cold Fusion and ASP Co-Servers



ScreenSurfer Variables provide you the ability to maintain information about an active session as well as global (server-wide) data. Since ScreenSurfer's URL generation capabilities always include the SessionKey, the state of variables is maintained for you; all that is required is to define and use the variables.

New Skills

ScreenSurfer variables provide the following features:
  • State management; variables and values are maintained from the start of a session through to termination, regardless of the number of interactions out and back to the browser
  • The <TEDECLARE tag provides documentation of a variable's type and size
  • Fixed text sizes match characteristics of a corresponding 3270 field
  • With <TEDECLARE, a variable initialization value can be provided which will initialize the variable at the start of a session
  • ScreenSurfer variables are polymorphic; regardless of the type specified for a variable, it may be used in any expression (text, floating-point or integer)

A complete description of ScreenSurfer variables and reserved internal variables may be found in the ScreenSurfer Variables Reference --this should be read prior to proceeding in this lesson.

Defining three types of variables Based on what you read in the variables reference section, you will define three variables, each one with different characteristics:
  1. Create a new file in /ScreenSurfer/hostserver/templates named vars.stml
  2. Add three <TEDECLARE statements at the top of the file which describe three variables:
    Name Type Size Initial Value
    User Text 10 (none)
    LogonStatus Integer n.a. 1
    GPA Float n.a. 3.24
  3. Save the file but keep the editor window open for further exercises

Server Scope Variables
Server scope variables are useful for maintaining values that are used by all sessions, while providing efficient storage. A server variable is always declared and used with the reserved string server. as the variable's prefix.

Another use for a server variable is that server variables are the only kind available when there is no active session. For example, if you want to use a global variable to maintain the host connection name (for example, LU_GROUP_1 vs. LU_GROUP_2), you can use a server-scope variable to set the group name, and use it in the <TEACTION CONNECT> tag.

Following is an exercise to create a server-scope variable for maintaining the LU group for a connection
Defining and using a server-scope variable
  1. At the top of the vars.stml file, insert the following line:
    <TEDECLARE VAR Server.ConnectName
          type=Text length=10
          data="LU_GROUP_1">
    
  2. Now, after the other variable definitions created in the prior skill exercise, add a new user transaction section:
    <TESECTION TestConnect
       WHEN tranpath_1 is "test"
        AND tranpath_2 is "it">
    <TEACTION CONNECT Server.ConnectName>
    <TESET Server.ConnectName="LU_GROUP_2">
    </TESECTION>
    
  3. Use the DevCenter to compile your templates
  4. Open or set focus to a browser window
  5. Enter the following URL: http://127.0.0.1/surfer/test/it (include a port following the 127.0.0.1 local machine address if ScreenSurfer is listening on something other than port 80)
  6. You should see the initial screen of the host you have defined as the first group (which should be the "toy mainframe")
  7. Click on the exit link
  8. Now, Enter the "test/it" URL again--you will now be connected to the second host defined...

Using a variable to store HTML
At times it may be useful to construct HTML text and place it in a variable. An example would be a SELECT tag with a number of options, where you want to maintain the options in a specific SurferScript template to make maintenance easier. Note that this approach also allows the use of ODBC datasources to construct an option list while reducing the database access overhead to a minimum.

Using a variable to store HTML
  1. In the vars.stml file, add the following declaration:
    <TEDECLARE VAR Server.MajorSelect
       type=text length=2000
       data='<select name="Major" size="1">
       <option value="English">
       <option value="Math">
       <option value="Equatorial Studies">
       </select>'>
    
  2. Add the following section:
    <TESECTION TestSelect
       WHEN tranpath_1 is "test"
        AND tranpath_2 is "select">
    <HTML>
    <BODY>
    <FORM>
    <TESHOW Server.MajorSelect>
    </FORM>
    </BODY>
    </HTML>
    </TESECTION>
    
Understanding SurferScript Expressions

SurferScript Expressions
ScreenSurfer expressions provide you with the ability to manipulate text and numeric values. For example, you can add two integer variables together to produce a sum for display to the user. There are three types of expressions in ScreenSurfer:

  • Text Expressions
  • Integer Expressions
  • Floating-point Expressions
The type of an expression is a function of the expression's context and contents. For example, the following tag will produce the result "234" instead of "9":
<TESHOW 2+"3"+4>
How is this so? The reason is that all values in ScreenSurfer are polymorphic, which means that regardless of the type of a value (whether a literal or a variable) it can always provide a text string, integer or floating point value. This provides efficiency in the storage of variables combined with freedom in their use (you don't have to worry about conversion from one type to another).

Ambiguous situations occur when the expression has a mix of types, such as the integer and text literals in the prior example. In this case, the type of the expression will be based on the most complex value in the expression, climbing from most simple (integer) to next (float) to most complex (text). In other words, if you have three integer values and one float, you will have a floating-point expression; if you have three integers and one text value, you will have a text expression.

Math Precedence

SurferScript expressions support standard math precedence for the four allowed operators add ("+"), subtract ("-"), multiply ("*") and divide ("/"). When you mix these operators in any expression, the natural order of precedence will be enforced by ScreenSurfer, whereby multiply and divide operations will be performed prior to add and subtract operations. For example, 2+3*4 will result in a value of 14.

You can enforce any order of precedence in your expressions by using parenthesis to group values and ensure a specific result. For example, (2+3)*4 will result in a value of 20.

Text Expressions

A text expression as a formula in a <TESET or in any situation where a tag expects a text value consists primarily of a text literal value (or any variable) optionally concatenated with one or more additional text values. The concatenation of text values is achieved with the plus (+) symbol. Note that there is a variety of text manipulation functions documented in the SurferScript Reference, including TextLeft("source", length), TextRight("source",length) and TextMid("source",start,length).

Here are some examples:

<TEACTION ENTER web.input+"[erase eof][enter]">
<TEACTION ENTER "AU "+SearchWords+"[enter]">
<TESET screen_text1 = TextMid(screen_text,3,1)>
Understanding Boolean Expressions

Boolean Expressions
Decisions in SurferScript are made primarily in the <TEIF> and <TEELIF> tags using Boolean Expressions. SurferScript boolean expressions are similar to those in other languages such as BASIC and C, whereby there is a left value, a compare and a right value. The following symbols are allowed for comparison:

SymbolUse
=is EQUAL TO
==is EQUAL TO
" IS "is EQUAL TO
!=is NOT EQUAL to
<>is NOT EQUAL to
>is GREATER THAN
<is LESS THAN
>=is GREATER THAN or EQUAL TO
<=is LESS THAN or EQUAL TO
Note that "alias" symbols are allowed to provide ease of use for those coming from a variety of language environments. Also, the "IS" token must have "whitespace" surrounding it (either one or more blanks, tab characters or line breaks).

Multiple comparisons may be combined with the following symbols:

SymbolUse
OR OR
|| OR
AND AND
&& AND

As with other language environments, you can provide precedence in the evaluation of BOOLEAN expressions using opening and closing parenthesis characters.

Example:

<TEIF (web.name=="Joe" OR web.name=="Joseph")
     AND web.PIN=="2116">
  <TESHOW "Hello Joe">
<TELIF web.name=="Mary"
     AND web.PIN=="1155">
  <TESHOW "Hello Mary">
<TEELSE>
  <TESHOW "Go Away Imposter!">
  <TEACTION RETURN>
</TEIF>   

Lesson 5. Key ScreenSurfer HTML TagsLesson 7. Logic and control