SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

Example 1-4 NEWS Headline Program Example

// To present the top news story from CNN.COM 
// Note:  From time to time CNN changes its format, so the 
//        main$  and  end_main$  sometimes have to be changed. 
 
  main$ = '<div class="CNN_homeBox">' 
  end_main$ = '</div>' 
 
  begin_form$ = '<form>' + 
                  '<h1><font color=green>' + 
                  'Top News from CNN' + 
                  '</font></h1>' + 
                  '<br><h2>' 
 
  news_ch = _channel 
  open #news_ch: name 'http://www.cnn.com' 
 
  crlf$=chr$(13)+chr$(10) 
  state$ = 'find_main' 
  do
    line input #news_ch, eof eof?: text$ 
    if eof? then exit do
    select case state$ 
    case 'find_main' 
      z0 = pos(text$, main$) 
      if z0 = 0 then repeat do
      z0$ = mid(text$, z0+len(main$)) 
      z0  = pos(z0$, '>') 
      if z0 = 0 then repeat do
      z0$ = mid(z0$, z0+1) 
      dbox$ = begin_form$ +z0$ 
      state$ = 'gather_news' 
    case 'gather_news' 
      z0 = pos(text$, end_main$) 
      if z0 > 0 then
        dbox$  = dbox$ + left(text$, z0-1) 
        state$ = 'show_news' 
        repeat do
      end if
      dbox$ = dbox$ + text$ + crlf$ 
      repeat do
    case 'show_news' 
      // first add in the  http://www.cnn.com  to any anchors 
      dbox$ = replace$(dbox$, '<a href="==<a href="http://www.cnn.com/',',', '==') 
      // now finish off the input form with a single "submit" button 
      dbox$ = dbox$ + '</h2><p><input type=submit></form>' 
      line input dialogbox dbox$: ans$ 
      exit do
    end select
  loop
  end

Example 1-5 Expression Evaluator Program Example

// Evaluate an expression 
// Type in the expression and press [enter] 
// 
// The expression can by very complex.  For example: 
//       ((34-324)/14)*10.1234 
 
  declare dynamic answer 
 
  formtop$= '<sheerpower persist>' + 
                  '<title>Expression Evaluator</title>' + 
                  '<form><h2>Enter an expression</h2>' + 
                  'For example--> ((344574647-324978)/154574)*13350.1234' + 
                  '<input name=expr submit>' + 
                  '<p>' 
 
  formend$ = '<p><input type=submit name=submit value="Submit">' + 
    '<input type=submit name=exit value="Exit"></form>'   
           
  form$ = formtop$ + formend$ 
  do
    input dialogbox form$: response$ 
    if _exit then exit do
    z0$ = element$(response$, 1, chr$(26))  // get the first field 
    expr$ = element$(z0$, 2, '=')          // get the data for the first field   
    if expr$ = '' then repeat do
    when exception in
      answer = eval(expr$) 
    use
      answer = extext$ 
    end when
    if dtype(answer) <> 1 then answer = str$(answer) 
    form$ = formtop$ + 
                  '<h2><font color=green>' + expr$ + '</font></h2>' + 
                  '<h3>' + answer + '</h3>' + 
                  formend$ 
  loop
  end

1.5 Developing Professional Applications with SheerPower

SheerPower Rapid Development Environment makes professional application development easy with BUILT-IN TEMPLATES, and SPECIAL KEYSTROKES.

Some of SheerPower's features are:

Plus many more special keystrokes that enable a programmer to quickly and efficiently write clean, readable and accurate code.

See Appendix I, Developing Professional Applications with SheerPower for a detailed discussion on the special features built-in to SheerPower designed to save time and money when creating professional applications.

See Appendix F, Keystrokes for SheerPower Rapid Development Environment for a complete reference guide to the special keystrokes in SheerPower Rapid Development Environment.

1.6 Open Existing Files in SPDEV

If you need to open an existing file stored on your computer to read or edit in SPDEV, click on the Open icon in the toolbar---an open file folder. You can then choose the directory and file you want to open from the OPEN dialog box that appears.

You can also open an existing file by clicking on File in the SPDEV toolbar, then selecting Open from the drop down menu. The Open dialog box will appear:

1.7 Default file location and file types

Whether you are creating a new file or opening an existing file to edit in SheerPower Rapid Development Environment, the default folder location is c:\sheerpower. The default file type being created/searched for is any of the SheerPower program files (*.spsrc, *.int, *.spinc and *.inc).

To open a different file type, click on the down arrow beside the Files of type: field (located at the bottom of the dialog box). Choose All Files to see all of files of the specified type within that folder.

To search for a file or to save your file to a different folder (other than c:\sheerpower), click on the down arrow beside the Look in: field (located at the top of the dialog box) and choose the folder you wish to search/save in.

SPDEV can open ANY kind of file that is not binary data.

1.8 SheerPower Program Error Messages

If you make an error in your program, such as misspelling the word print:

Example 1-6 SheerPower program error message

  input 'Please enter your name' : name$ 
  printt 'Hello, '; name$ 
 
Build of C:\SheerPower\tests.spsrc 
file: C:\SheerPower\tests.spsrc 
    (line 2, column 0):  Unrecognized statement 

SheerPower will display an error message in the bottom frame of the window (the results window). You can double click on the line number given in the error message. SheerPower will highlight the line of code containing the error for you, and place the cursor at the beginning of the error. You can now retype the correction and rebuild your main source program.

1.9 SP4GL Console Window

When a main source program is run in SheerPower Rapid Development Environment, the SP4GL Console Window will open (also referred to as "console window").

To open the SP4GL Console Window without running a main source program, click on the SP4GL Console Window icon in the SPDEV toolbar---the square with a lightning bolt through it.

To close the SP4GL Console Window, type in exit and press the [Enter] key, or click the X in the top right corner of the window.

SP4GL Console Window

The console window must be closed before attempting to run a program again. The running man icon in the SheerPower Rapid Development Environment (SPDEV) toolbar will remain greyed out until the console window is closed.

More than one instance of the SP4GL Console Window can be opened by clicking on the SP4GL Console Window icon in the SPDEV toolbar.

1.9.1 SP4GL Console Window Keystrokes

In the console window the mouse can be used to select (highlight) text on the screen.

Below is a table containing the special keystrokes available when working in the SP4GL Console Window.

Table 1-1 SP4GL Console Window
Keystroke Function Performed
ctrl/a selects all text (both on and off screen)
ctrl/c places selected text into the clipboard
ctrl/m places contents of message history into the clipboard
ctrl/t places contents of screen (including scroll buffers) into the clipboard

1.10 Getting Help in SheerPower

In SPDEV, you can get help by clicking on the Help icon in the toolbar---a question mark.

You can get help when in the console window by typing help and pressing the [Enter] key or by clicking on the ? icon in the toolbar.

Selecting HELP in SPDEV or the console window will open up a new browser window that loads the online SheerPower documentation.

Utilize the Contents or the Index to help you find the required documentation.

1.11 Conventions Used in this Manual

User Conventions

In some places in this manual, the format of statements and commands is represented abstractly. For example:


  Format:     [LET] var = expr 

Certain conventions are used to represent values which you (the user) must supply. These conventions are always shown in lowercase. These are the user conventions:

Symbol Description
array Array element.
block of code A SheerPower statement or a series of SheerPower statements.
chnl An I/O channel associated with a file.
chnl_num An I/O channel associated with a file.
cond_expr Conditional expression.
col Column. Used in the TAB or AT option to indicate the column to print at.
const Constant value.
expr Expression. May be a variable, constant, array element, structure reference, etc. or any combination of the previous, separated by operators.
field_expr Field name expression.
func Function.
handl Exception handler. Pertaining to an exception handling routine.
handler The block of code in an exception handler which is executed when an exception is generated.
int Integer value.
int_expr Integer expression.
int_var Integer variable.
label Alphanumeric statement label.
libr Pertaining to libraries.
line_num Program line number.
name Name. Indicates the declaration of a name or the name of a program unit, such as a subprogram.
num Numeric value. Num indicates that either a real or integer numeric value may be used.
num_expr Numeric expression. Num_expr indicates that either a real or integer numeric value may be used.
num_var Numeric variable.
param An expression which is passed to a function, subprogram or other program unit. A parameter can be any valid SheerPower expression.
protected block The block of code protected by an exception handling routine.
real Real number. Indicates that only a real number may be used.
row Row. Used in the AT option to specify the row to print at.
str String. Str indicates that only a string value may be used.
str_expr String expression.
str_var String variable.
struc A SheerPower structure.
struc_name Structure name.
struc_expr Structure expression.
sub A SheerPower subprogram.
target The target point of a branch statement. The target can be either a program line number, an alphanumeric label, or a ROUTINE statement.
uncond_expr Unconditional expression. Uncond_expr indicates that only an unconditional expression can be used.
var Variable. May be a simple variable, array element or a structure reference.


Previous Next Contents Index