■ Exemples.
(10+2+5+7+8)/5
min(4,5,1,6,2)
pi*pow(2,2) (Surface d'un cercle de 2 cm de rayon)
4*pi*pow(2,2) (Surface d'une sphère de 2 cm de rayon)
■ Les fonctions actuelles.
pi, cos, acos, sin, asin, tan, atan, exp, log, max, min, pow, round
L'astuce consiste à utiliser JavaScript pour le retour du résultat. Vous pouvez ajouter facilement d'autres fonctionnalités.
Code : Tout sélectionner
EnableExplicit
Enumeration fonts
#fontGlobal
EndEnumeration
Enumeration window
#mf
EndEnumeration
Enumeration gadget
#web
#source
#send
EndEnumeration
Enumeration shortcuts
#enter
#escape
EndEnumeration
Global HTML.s, myBrowser.IWebBrowser2
; Summary
Declare send()
Declare setUrl(source.s)
Declare exit()
; Fonts
LoadFont(#fontGlobal, "", 14)
SetGadgetFont(#PB_Default, FontID(#fontGlobal))
; Form
OpenWindow(#mf, 0, 0, 500, 120, "Calculatrice ligne de commande", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; View Result
WebGadget (#web, 0, 0, 500, 80, "")
SetGadgetAttribute(#web, #PB_Web_BlockPopups, #True)
SetGadgetAttribute(#web, #PB_Web_BlockPopupMenu, #True)
myBrowser = GetWindowLong_(GadgetID(#web), #GWL_USERDATA)
myBrowser\put_Silent(#True) ;Suppress error warnings in WebGadget
myBrowser\put_Left(0)
; Enter user data & Send (Button Send or Enter)
StringGadget(#source, 5, 82, 405, 28, "0")
SetGadgetColor(#source, #PB_Gadget_BackColor, RGB(230, 230, 230))
ButtonGadget(#send, 415, 82, 80, 28, "Send")
GadgetToolTip(#send, "Enter")
SetActiveGadget(#source)
; Triggers
BindGadgetEvent(#send, @send())
AddKeyboardShortcut(#mf, #PB_Shortcut_Return, #enter)
BindEvent(#PB_Event_Menu, @send(), #mf, #enter)
BindEvent(#PB_Event_CloseWindow, @exit())
AddKeyboardShortcut(#mf, #PB_Shortcut_Escape, #escape)
BindEvent(#PB_Event_Menu, @exit(), #mf, #escape)
; Init WebGadget
Send()
; Loop
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Procedure send()
Protected buffer.s = GetGadgetText(#source)
Protected source.s
; A small preparation : We use the Javascript Math library
source = ReplaceString(buffer, "pi", "Math.PI", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "cos", "Math.cos", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "acos", "Math.acos", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "sin", "Math.sin", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "asin", "Math.asin", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "tan", "Math.tan", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "atan", "Math.atan", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "exp", "Math.exp", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "log", "Math.log", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "max", "Math.max", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "min", "Math.min", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "pow", "Math.pow", #PB_String_NoCase) : buffer = source
source = ReplaceString(buffer, "round", "Math.round", #PB_String_NoCase) : buffer = source
setUrl(source)
SetActiveGadget(#source)
EndProcedure
; Send & Exec source
Procedure setUrl(source.s)
; HTML
HTML = "<meta http-equiv='X-UA-Compatible' content='IE=edge' />"
HTML + "<body bgcolor='#E6E6E6' scroll=no>"
; result
HTML + "<div id='result' style='color:#000000; font-size:30px'>Oops Error !!</div>"
HTML + "</body>"
; JavaScript
HTML + "<script>" ;+ #CRLF$
HTML + "var buffer = " + source + ";"
; Result Area
HTML + "document.getElementById('result').innerHTML=buffer;"
HTML + "</script>"
SetGadgetItemText(#web, #PB_Web_HtmlCode , HTML)
EndProcedure
Procedure exit()
End
EndProcedure
- Touche Escape pour quitter l'utilitaire.
Enjoy