SheerPower® 4GL -- Beyond BASIC --

Sample Expression Evaluator Program

FREE!! Download SheerPower 4GL NOW! Documentation SheerPower 4GL Technical Support Options FAQ
Discussion Forum   Sample Programs Contact Us
Sample Progams Overview

Writing and Running the Sample Programs

Menu Program

A Simple Quiz

Expression Evaluator


SheerPower 4GL Home

Expression Evaluator Program

SheerPower 4GL has powerful expression evaluation features. Try writing this program in your current programming language!


// 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


Questions, comments and suggestions are welcome!



Copyright (c) 2003-2016 Touch Technologies, Inc. All rights reserved.
Parts of the SheerPower technology are U.S. patented under patent#s 6822586, 7149765, and 8164492