Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Evaluating a maths expression in a string?

From: mike:myers:cybarite at: 29-Dec-2000 18:34

>I'm sure it will be! Could you just give us a URL for that, Listar ate >the file attach.
Ouch! Here is the source clipped into mail. ======================================================================================================================== REBOL [ Title: "Calculator" File: %calculator.r Date: 11-December-2000 Author: [mike--myers--cybarite--com] Purpose: {Simple numeric calculator using VID Layout. Based on January 2000 REBOL/View Face Calculator by Carl Sassenrath. Adds memory ability.} ] memory: 0 set-memory: func [aValue] [ memory: aValue either aValue = 0 [memory-recall/edge/color: memory-recall-edge-default] [memory-recall/edge/color: green] show memory-recall ] evaluated?: false ; determines whether the calculation is clearing an old one or appending to it. evaluate: func [] [ evaluated?: true if error? try [ text-box/text: form evaluation: do text-box/text ][ text-box/text: "Error" evaluation: 0 ] show text-box return evaluation ] cell-size: 32x32 ; use one cell size and base all faces on that size via pair arithmetic face-size: cell-size - 4x4 ; calculator buttons size is less than cell size to give a border button-size: face-size * 2x1 + 4x0 ; standard buttons will be twice as wide as the calculator buttons text-box-size: cell-size * 5x1 - 4x8 ; the text box will be 5 columns wide page-size: cell-size * 7x10 ; the page will hold 7 columns and 10 rows calculator-styles: stylize [ operator-button: button face-size gray [ evaluated?: false append-entry rejoin [" " face/text " "]] number-button: button face-size gray [ if evaluated? [text-box/text: copy ""] evaluated?: false append-entry face/text] ] append-entry: func [entry [string!]] [ append text-box/text entry show text-box ] negate-text: func [] [ either "-" = pick text-box/text 1 [text-box/text: skip head text-box/text 1] [text-box/text: rejoin ["-" text-box/text]] ] calculator-layout: layout [size page-size styles calculator-styles across backdrop gray at cell-size * 1x1 text-box: field "" right text-box-size at cell-size * 1x3 operator-button "(" #"(" at cell-size * 2x3 operator-button ")" #")" return at cell-size * 3x3 arrow face-size gray left keycode [left #"^(back)"] ; backspace one character [text-box/text: head clear back tail text-box/text show text-box] at cell-size * 4x3 number-button "C" keycode [#"C" #"c"] [clear text-box/text show text-box] at cell-size * 5x3 operator-button "MC" [set-memory 0] at cell-size * 1x4 number-button "7" #"7" at cell-size * 2x4 number-button "8" #"8" at cell-size * 3x4 number-button "9" #"9" at cell-size * 4x4 operator-button "/" #"/" at cell-size * 5x4 memory-recall: operator-button "MR" [append-entry form memory] at cell-size * 1x5 number-button "4" #"4" at cell-size * 2x5 number-button "5" #"5" at cell-size * 3x5 number-button "6" #"6" at cell-size * 4x5 operator-button "*" #"*" at cell-size * 5x5 operator-button "MS" [set-memory evaluate] at cell-size * 1x6 number-button "1" #"1" at cell-size * 2x6 number-button "2" #"2" at cell-size * 3x6 number-button "3" #"3" at cell-size * 4x6 operator-button "-" #"-" at cell-size * 5x6 operator-button "M+" [set-memory memory + evaluate] at cell-size * 1x7 number-button "0" #"0" at cell-size * 2x7 number-button "+/-" [negate-text show text-box] at cell-size * 3x7 number-button "." #"." at cell-size * 4x7 operator-button "+" #"+" at cell-size * 5x7 operator-button "=" keycode [#"=" #"^M"] [ evaluate] at cell-size * 1x9 button button-size "About" [view/new/offset about 10x10] at cell-size * 4x9 button button-size "Done" [unview/only calculator-layout] ] about: layout [ backdrop black size 500x280 across return title "About" return text rejoin ["Title: " form system/script/header/title] return text rejoin ["Author: " form system/script/header/author] return text rejoin ["Purpose: " form system/script/header/purpose] return text {Enter numbers or operators shown using keyboard or mouse clicks. } return text red {Warning - Brackets are needed for precedence of arithmetic operations.} return text red {Otherwise 2 + 3 * 5 = 25. Use 2 + (3 * 5) = 17} return button "OK" keycode [#"^(ESC)" #" "] [unview] ] memory-recall-edge-default: memory-recall/edge/color view calculator-layout [mike--myers--cybarite--com]