GLL Example: Using Eval()

Evaluate an expression using Eval().

Input from inside a GLL routine can be performed with InputBox() or Prompt. This example uses the GFA-BASIC 32-Function Eval to calculate a mathematical expression. The result is then displayed in a message box.

 

Sub Gfa_Ex_Y    ' SHIFT+CTRL+Y

Local a$, x#

a = InputBox("Give an expression")

If Len(a)

//Try

x = Eval(a)

MsgBox "The result is" & x

//Catch

//  MsgBox "error"

//EndCatch

EndIf

EndSub

Rather than use an input box you could use selected text and then replace the selection with the evaluation result

' SHIFT+CTRL+Z

 

Sub Gfa_Ex_Z

Try

Gfa_Insert Eval(Gfa_Selection)

Catch

EndCatch

EndSub

{Created by Sjouke Hamstra; Last updated: 08/10/2014 by James Gaite}