SheerPower® 4GL -- Beyond BASIC --

Professional Software Development Tutorial

FREE!! Download SheerPower 4GL NOW! Documentation SheerPower 4GL Technical Support Options FAQ
Discussion Forum Voice Tours and Tutorials Sample Programs Contact Us
Getting Started

Creating Programs

A Sample Program

Deploying Programs

Running Programs

Sharing Programs


SheerPower 4GL Home

Professional Software Development

The SheerPower Rapid Development Environment makes it fun to write professional, efficient, and easy-to-maintain programs. Some major features include:
  • Automatic program template generation via GOLD/P keystroke.
  • Automatic routine template generation via GOLD/R keystroke.
  • Automatic Routine organization by either calling order or alphabetical via GOLD/O keystroke.
  • Automatic source code indentation and custom coloring of keywords, functions, modifiers, and other program elements.
  • Routine documentation assistance via GOLD/D keystroke.
  • Almost instant program compiles -- speeds in excess of 200,000 lines of code per second.

The purpose of this example is to illustrate the special keystrokes and other features of SheerPower Rapid Development Environment that enable a programmer to easily and quickly create professional programs.

To start SheerPower Rapid Development Environment (SPDEV), double click the SheerPower shortcut icon located on your desktop---a circle with a lightning bolt through it.

To create a new program in SheerPower Rapid Development Environment, click once on the New icon in the toolbar---a white paper with one corner folded.

Name your new program file news.spsrc and click on [SAVE]inside the Name New File... dialog box.

A dialog box will also appear prompting you for your name, company name and program name.

When you fill in this information and click on [OK], a program template will automatically be inserted into your new program file.

Note

You can change your name, company name and initials at anytime by clicking on Options in the SPDEV toolbar, then selecting Change System Settings.

You are now ready to write a professional application in SheerPower.

Program Template

A PROGRAM TEMPLATE can also be created instantly inside a program file by using the GOLD/P keystroke inside SheerPower Rapid Development Environment (SPDEV).

The GOLD Key referred to in this section is a special key used to create many of the specialized keystrokes within SPDEV. Both the [Esc] (escape key - top left corner of the keyboard) and the [Num-Lock] (numbers lock key in the numeric keypad) are GOLD keys in SheerPower Rapid Development Environment.

To use the GOLD key, press either GOLD key ([Esc] or [Num-Lock]), let go, then continue with the rest of the keystroke to complete the function.

Example - Program Template

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! Program: Name of program 
! System : 
! Author : Your name 
! Company: Company name 
! Date   : June 30, 2002 
! Purpose: 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
!         I n i t i a l i z a t i o n 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
!         M a i n   l o g i c   a r e a 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
 
stop 
 
 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
!         R o u t i n e s 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 
 
end 
 

Your cursor will be positioned at the top section of the template beside Purpose:. You can type in the purpose of the program being written here. The purpose of news.spsrc (this example program) is: To present the top news story from CNN.COM.

SPDEV automatically fills in the name of the program, the author and company names, and the date for you when the template is created.


!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! Program: news 
! System : 
! Author : Your name 
! Company: Company name 
! Date   : June 30, 2002 
! Purpose: To present the top news story from CNN.COM 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

Copy and paste the following SheerPower code underneath the Initialization heading.


// Note:  From time to time CNN changes its format, so the 
//        main$  and  end_main$  sometimes have to be changed. 
 
main$ = '<div class="cnnT1Hd' 
end_main$ = '</div>' 
 
begin_form$ = '<form>' + 
              '<h1><font color=green>' + 
              'Top News from CNN' + 
              '</font></h1>' + 
              '<br><h2>' 

Copy and paste the following code underneath the Main logic area heading above the word stop.


news_ch = _channel 
open #news_ch: name 'http://www.cnn.com' 
get_headline 

Now you are ready to write the routines that create news. spsrc.

Programs are made up of ROUTINES. Each routine has its own heading with details on what the purpose of the routine is, and how it works.

Creating a Routine Header Template

Place your cursor underneath the Routines heading. Press the [GOLD] key (either [Esc] or [Num-Lock]), and let go. Then press [R]. You will see the following prompt:

Type get_headline inside the empty field beside Routine Name:.

Note

All routine names must contain at least one underscore (_).

The Optional Parameters section contains the following fields:

Routine Template-Optional Parameters
Parameter Description
With: parameters being passed into the routine.
Returning: parameters returned as a result of running the routine.
Private: variables that can only be accessed from inside this routine.

You can leave the Optional Parameters fields blank for the purpose of this tutorial.

Click on [OK]. The ROUTINE HEADER TEMPLATE will appear.

Example - Routine Header Template

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!   
! 
! Expected on entry: 
! 
! 
! Locals used: 
! 
! 
! Results on exit: 
! 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
routine get_headline 
 
end routine 

There are four fields to complete inside the Routine Header Template:

  • Brief description - describe the purpose of the routine.
  • Expected on entry - list variable names and the data they store that are coming into the routine (already defined).
  • Locals used - list any variables defined in this routine only and the data they store.
  • Results on exit - list any variables defined in this routine that will be used elsewhere in the program. Include what the result of the routine will be on exit.

Here is the completed routine header for this routine:


!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! g e t _ h e a d l i n e 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!   Go out to www.cnn.com and extract the headline of the top 
!   news story. 
! 
! Expected on entry: 
!   main$       = the starting point of the headline 
!   begin_form$ = the top HTML code for the dialogbox form 
!   end_main$   = the end point of the headline 
! 
! Locals used: 
!   text$  = the HTML code on the CNN website 
!   crlf$  = contains the character line feeds 
!   state$ = tells which action needs to be 
!            performed next on the incoming data 
! 
! Results on exit: 
!   dbox$  = stores the code to create the dialogbox 
! 
!   The headline is found and the form is created. 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

Copy and paste the following SheerPower code into the get_headline routine on a blank line in between routine get_headline and end routine. The first line of code is indented 2 spaces under the routine statement with the rest of the code indented accordingly below.


  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><input type=submit></form>' 
      line input dialogbox dbox$: ans$ 
      exit do 
    end select 
  loop 

Using GOLD/R to Make Subroutines

Often routines can get to be too long and complicated. SheerPower makes it easy to make subroutines from within a routine. Just highlight the code you want to move into a subroutine and press [GOLD][R]. You will be prompted to type in a name for the subroutine. Type in the name and press [OK]. SheerPower will move the highlighted code into a new subroutine below the original routine instantly.

In the news.spsrc example, we will illustrate how this is done.

Inside the news.spsrc program file, highlight the following section of SheerPower code near the bottom of the program:


    // 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><input type=submit></form>' 

Now press [GOLD][R]. The New Routine dialog box will appear. Type the name of the subroutine being created as complete_form.

You can leave the Optional Parameters fields blank for the purpose of this tutorial.

Click on [OK]. SheerPower will take the highlighted code from the original routine, and create a new routine below the first one containing the highlighted code.

SheerPower will also insert the CALL for the subroutine inside the original routine.

The completed routine header for complete_form is as follows:


!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! c o m p l e t e _ f o r m 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
! 
! Brief description: 
!   Add the CNN URL to anchors and complete the form with the submit 
!   button. 
! 
! Expected on entry: 
!   dbox$ = stores the code to create the dialogbox 
! 
! Locals used: 
!   none 
! 
! Results on exit: 
!   Any anchors are now complete with the CNN URL and the form 
!   is completed. 
! 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

Running the Example Program

RUN this program by clicking on the Run icon in the SPDEV toolbar---the running man.

The program goes out to www.cnn.com and grabs the latest headline for the top news story, then displays it in a form window with a clickable link to the complete story.

Routine Definitions

To make it easier to locate routines and find out what they do inside large programs, SPDEV has two specially mapped keys to assist:

F12: Show definition

F11: Go to definition

F12 - Show definition

The F12 key displays the routine header information inside a new window. This feature especially benefits maintenance programmers.

You can place your cursor on the reference to any routine name inside a program, press [F12] and a new window will appear containing the routine definition (header information).

Inside the example program news.spsrc place your cursor on the reference to the routine get_headline in the Main logic area.


!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
!         M a i n   l o g i c   a r e a 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
news_ch = _channel 
open #news_ch: name 'http://www.cnn.com' 
get_headline    //<--- place your cursor on this routine reference 
 
stop 

Now press the [F12] key. The following new window will appear:

The special F12 keystroke allows you to find the details about any routine in a program without having to go to the actual routine.

F11 - Go to definition

The F11 key takes you directly to a routine when you place your cursor on the reference to that routine.

Inside the example program news.spsrc place your cursor on the reference to the routine get_headline in the Main logic area.


!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
!         M a i n   l o g i c   a r e a 
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
news_ch = _channel 
open #news_ch: name 'http://www.cnn.com' 
get_headline    //<--- place your cursor on this routine reference 
 
stop 

Now press the [F11] key. You will automatically be taken to the start of the get_headline routine.

To get back to where you were simply press GOLD/B.

See the SheerPower 4GL Documentation for more details on all the special programming keystrokes built into the SheerPower Rapid Development Environment.

Using GOLD/O to Organize Routines

Routines can become logically out of order as a program is being written, making it hard to follow program logic and hard to find a given routine.

In SPDEV, the GOLD/O keystroke lets you automatically order your routines in either calling order or alphabetical order.

Inside the example program news.spsrc place your cursor anywhere and press the GOLD key ([Esc]), let go, then press the O key. The Organize Code dialog box will appear.

The routines in news.spsrc are currently organized in calling order. Select Alphabetically.

Routine complete_form will now be first in the program, and get_headline will be last. Press GOLD/O again and choose in calling order. Then click on [OK]. The routines will now be organized in their calling order.

See the SheerPower 4GL Documentation for more details on all the special programming keystrokes built into the SheerPower Rapid Development Environment.


Questions, comments and suggestions are welcome!



Copyright (c) 2003-2010 Touch Technologies, Inc. All rights reserved.
Parts of the SheerPower technology are U.S. patented and patent pending.