Script Library: 1247 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Archive version of: supercalculator.r ... version: 2 ... crazyaxe 17-Feb-2010

Rebol [
	title: "Supercalculator"
	author: "Massimiliano Vessi"
	date:  17/02/2010
	email: maxint@tiscali.it
	file: %supercalculator.r
	Purpose: {"Scientific calculator in Rebol!"}
	;following data are for www.rebol.org library
	;you can find a lot of rebol script there
	library: [ 
		level: 'beginner 
		platform: 'all 
		type: [tutorial  tool] 
		domain: [vid gui  text-processing ui user-interface scientific] 
		tested-under: [windows linux] 
		support: none 
		license: [gpl] 
		see-also: none 
		] 
	version 1.3.2
	]

risultato2: " "

valuta: func [frase][
	frase: to-string frase
	replace/all frase "*"  " ) * ( "
	replace/all frase "/"   " ) / ( "
	replace/all frase "+"   " )) + (( "
	replace/all frase "-"   " )) - (( "
	replace/all frase "^^"   "  **  " ;bad change, but necessary
	replace/all frase "exp"   "  exp  "
	replace/all frase "log"   "  log-10  "
	replace/all frase "ln"   "  log-e  "
	replace/all frase "sqrt"   "  square-root  " ;bad change, but necessary
	replace/all frase "absolute"   "  absolute  "
	replace/all frase "sin"   "  sine  " 
	replace/all frase "cos"   "  cosine  "
	replace/all frase "tangent"   "  tangent  "
	replace/all frase "arcs"   "  arcsine  " ;bad change, but necessary
	replace/all frase "arcc"   "  arccosine  " ;bad change, but necessary
	replace/all frase "arct"   "  arctangent  " ;bad change, but necessary
	insert frase " (( "
	append frase " )) "	
	;frase: head frase
		
	;print frase
	
	risultato: do frase 
	
	;print risultato
	;restore the origina string
	replace/all frase    "  **  " "^^"
	replace/all frase   "  arcsine  "  "arcs" 
	replace/all frase    "  arccosine  " "arcc"
	replace/all frase   "  arctangent  " "arct" 
	replace/all frase    "  square-root  " "sqrt"
	replace/all frase    "  sine  "  "sin"
	replace/all frase   "  cosine  " "cos" 
	replace/all frase    "  log-10  " "log"
	replace/all frase    "  log-e  " "ln"
	
	replace/all  frase " ) " "" ;remove al simple parenthesis
	replace/all  frase " ( " "" ;remove al simple parenthesis
	replace/all  frase " (( " "" ;remove al double parenthesis
	replace/all  frase " )) " "" ;remove al double parenthesis
	
	
	pretty_frase: trim/all frase
	risultato2: head risultato2
	risultato2: insert risultato2  (reform [ "^/" pretty_frase "^/----------^/" risultato "^/"])
	risultato2: head risultato2
	return risultato2
	]



solve_all: func [] [
	
	]

view layout [

	text "History:"
	a_field: area 255.255.100
	return
	guide
	text "Write expression below:"
	b_field: field [ a_field/text: to-string (valuta b_field/text)
		if  b_field/text = "" [ b_field/text: "0"]
		b_field/text: copy []
		b_field/text: to-string b_field/text
		show [ a_field b_field]
		]
	across	
	button 20x20 "1" [ append b_field/text "1"  show b_field]
	button 20x20 "2" [ append b_field/text "2"  show b_field]
	button 20x20 "3" [ append b_field/text "3"  show b_field]
	button 20x20 "+" [ append b_field/text "+"  show b_field]
	button 20x20 "-" [ append b_field/text "-"  show b_field]
	button "sin"  40x20 [ append b_field/text "sin"  show b_field]
	button "cos" 40x20 [ append b_field/text "cos"  show b_field]
	button "tan" 40x20 [ append b_field/text "tangent"  show b_field]
	return
	button 20x20 "4" [ append b_field/text "4"  show b_field]
	button 20x20 "5" [ append b_field/text "5"  show b_field]
	button 20x20 "6" [ append b_field/text "6"  show b_field]
	button 20x20 "*" [ append b_field/text "*"  show b_field]
	button 20x20 "/" [ append b_field/text "/"  show b_field]
	button "asin"  40x20 [ append b_field/text "arcs"  show b_field]
	button "acos" 40x20 [ append b_field/text "arcc"  show b_field]
	button "atan" 40x20 [ append b_field/text "arct"  show b_field]
	return
	button 20x20 "7" [ append b_field/text "7"  show b_field]
	button 20x20 "8" [ append b_field/text "8"  show b_field]
	button 20x20 "9" [ append b_field/text "9"  show b_field]
	button 20x20 "0" [ append b_field/text "0"  show b_field]
	button 20x20 green "=" [ 
		if  b_field/text = "" [ b_field/text: "0"]
		a_field/text: to-string (valuta b_field/text)
		b_field/text: copy []
		b_field/text: to-string b_field/text
		show [ a_field b_field]
		]
	button  "log" 30x20 [ append b_field/text "log"  show b_field]	
	button  "ln" 30x20 [ append b_field/text "ln"  show b_field]	
	button  "e^^" 30x20 [ append b_field/text " exp "  show b_field]	
	button  "abs" 31x20  [ append b_field/text "abs"  show b_field]	
	return
	button 20x20 "." [ append b_field/text "."  show b_field]
	button 20x20 " ^^ " [ append b_field/text "^^"  show b_field]
	button   42x20 "SQRT" [ append b_field/text "sqrt"  show b_field]
	button 30x20 "EE" [ append b_field/text "e"  show b_field]
	button red 30x20 "CC" [ b_field/text: copy []   show b_field]
	
	]