description: permet de lire des fichier contenant une formule et de l'appliquer bêtement
niveau: simple
screen en bas du post
► Afficher le textecode
Code : Tout sélectionner
opt("guioneventmode",1)
$f=""
for $i=1 to ubound ($cmdline) -1 step 1
$f&=$cmdline[$i]
if stringinstr($f,".") then ExitLoop
Next
if $f="" then $f=FileOpenDialog("fichier de formule","","formule (*.frl)")
if $f="" then exit
$temp=IniReadSectionNames($f)
global $title=$temp[1] ; "gaz parfait"
global $formule=iniread($f,$temp[1],"formule","null") ;"P=N*8.314472*T/V"&@crlf&"V=N*8.314472*T/P"&@crlf&"N=P*V/(8.314472*T)"&@crlf&"T=P*V/(8.314472*N)"
global $cont= iniread($f,$temp[1],"varlist","null"); "PVNT"
if $cont="null" or $formule="null" then Exit
$f1=stringsplit($formule,"|",1)
global $index = stringlen($cont)
global $list=stringregexp($cont,".",3)
global $label[$index]
global $input[$index]
global $radio[$index]
global $height=($index) * 17
global $unknow=-1
global $t=timerinit()
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("["&$title&"]", 178, $height, 190, 121)
for $i=0 to $index-1 step 1
$Label[$i] = GUICtrlCreateLabel($list[$i]&"=", 0, 17*$i, 17, 17)
$Input[$i] = GUICtrlCreateInput("", 24, 17*$i, 129, 17)
$Radio[$i] = GUICtrlCreateRadio("", 160, 17*$i, 17, 17)
guictrlsetonevent($Radio[$i],"sel")
Next
guisetonevent($GUI_EVENT_CLOSE,"_exit")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
TrayTip("commentaire de l'auteur",IniRead($f,$title,"com","aucun"),20000)
while 1
if $unknow <> -1 and timerdiff($t) > 500 then
for $i = 0 to $index step 1
if stringleft($f1[$i],1) == stringleft(guictrlread($Label[$unknow]),1) then
$calc=$f1[$i]
ExitLoop
EndIf
Next
for $i = 0 to $index - 1 step 1
$v = GUICtrlRead($Input[$i])
if $i <> $unknow then $calc=stringreplace($calc,$list[$i],"("&$v&")",0,1)
Next
$c=execute(stringtrimleft($calc,2))
guictrlsetdata($input[$unknow],$c)
$t=timerinit()
EndIf
WEnd
func sel()
for $i=0 to stringlen($formule)-2 step 1
if @GUI_CtrlId = $Radio[$i] then
if $unknow <> -1 then guictrlsetstate($Input[$unknow],$GUI_ENABLE)
guictrlsetstate($Input[$i],$GUI_DISABLE)
$unknow=$i
ExitLoop
EndIf
Next
EndFunc
func _exit()
Exit
EndFunc
description: permet de créer un fichier de formule (applicable par frl reader)
niveau: simplissime
► Afficher le textecode
Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("frl creator", 194, 251, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 193, 177)
GUICtrlSetData(-1, "bienvenue dans l'asistant de "&@crlf&"création de frl pour créer des ficher "&@crlf&"de formule"&@crlf&"pour commencer, saisissez les "&@crlf&"variable de la formule"&@crlf&"par exemple pour la loi des gaz "&@crlf&"parfait PV=NRT, R est une "&@crlf&"constante, on saisie PVNT")
GUICtrlSetstate(-1,$gui_disable)
$Button1 = GUICtrlCreateButton("suite", 136, 224, 57, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 0, 224, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
while GUIGetMsg() <> $Button1
if GUIGetMsg()=$gui_event_close then exit
WEnd
global $cont = GUICtrlRead($input1)
global $sc=stringregexp($cont,".",3)
GUIDelete($form1)
$f=$sc[0]&"="&InputBox("formule "&0,"saisissez l'expression de "&$sc[0])
for $i=1 to ubound($sc)-1 step 1
$f&="|"&$sc[$i]&"="&InputBox("formule "&$i,"saisissez l'expression de "&$sc[$i])
Next
$n="000000000000000000"
while stringlen($n) > 12
$n=InputBox("nom","quel est le nom de la formule ?")
if stringlen($n) > 12 then MsgBox(0,"erreur","c'est trop long ! (11 chr max)")
WEnd
$com=InputBox("commentaire","voulez vous ajouter un commentaire ?")
$fi=FileSaveDialog("fichier généré, sauvegarder où ?","","formule (*.frl)")&".frl"
IniWrite($fi,$n,"formule",$f)
IniWrite($fi,$n,"varlist",$cont)
IniWrite($fi,$n,"com",$com)
MsgBox(0,"sauvegarde terminé","")
description: donne la masse molaire d'une molécule
niveau: moyen
screen en bas du post
► Afficher le textecode
Code : Tout sélectionner
global const $H = 1.0079
global const $He = 4.0026
global const $Li = 6.941
global const $Be = 9.0122
global const $B = 10.811
global const $C = 12.011
global const $N = 14.007
global const $O = 15.999
global const $F = 18.998
global const $Ne = 20.180
global const $Na = 22.990
global const $Mg = 24.305
global const $Al = 26.982
global const $Si = 28.086
global const $P = 30.974
global const $S = 32.065
global const $Cl = 35.453
global const $Ar = 39.948
global const $K = 39.098
global const $Ca = 40.078
global const $Sc = 44.956
global const $Ti = 47.867
global const $V = 50.942
global const $Cr = 51.996
global const $Mn = 54.938
global const $Fe = 55.845
global const $Co = 58.933
global const $Ni = 58.693
global const $Cu = 63.546
global const $Zn = 65.38
global const $Ga = 69.723
global const $Ge = 72.64
global const $As = 74.922
global const $Se = 78.96
global const $Br = 79.904
global const $Kr = 83.798
global const $Rb = 85.468
global const $Sr = 87.62
global const $Y = 88.906
global const $Zr = 91.224
global const $Nb = 92.906
global const $Mo = 95.96
global const $Ru = 101.07
global const $Rh = 102.91
global const $Pd = 106.42
global const $Ag = 107.87
global const $Cd = 112.41
global const $In = 114.82
global const $Sn = 118.71
global const $Sb = 121.76
global const $Te = 127.60
global const $I = 126.90
global const $Xe = 131.29
global const $Cs = 132.91
global const $Ba = 137.33
global const $La = 138.91
global const $Ce = 140.12
global const $Pr = 140.91
global const $Nd = 144.24
global const $Sm = 150.36
global const $Eu = 151.96
global const $Gd = 157.25
global const $Tb = 158.93
global const $Dy = 162.50
global const $Ho = 164.93
global const $Er = 167.26
global const $Tm = 168.93
global const $Yb = 173.05
global const $Lu = 174.97
global const $Hf = 178.49
global const $Ta = 180.95
global const $W = 183.84
global const $Re = 186.21
global const $Os = 190.23
global const $Ir = 192.22
global const $Pt = 195.08
global const $Au = 196.97
global const $Hg = 200.59
global const $Tl = 204.38
global const $Pb = 207.2
global const $Bi = 208.98
global const $Th = 232.04
global const $Pa = 231.04
global const $U = 238.03
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("masse molaire", 386, 46, 192, 124)
$Input1 = GUICtrlCreateInput("", 0, 0, 385, 21)
$Input2 = GUICtrlCreateInput("résultat", 0, 24, 385, 21)
GUICtrlSetState($Input2,$GUI_disable)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
MM()
if GUIGetMsg()=$GUI_EVENT_CLOSE then Exit
WEnd
func MM()
local $reg
$str=GUICtrlRead($Input1) ; on lit les donnée de la boite 1
if StringRegExp($str,"[^0123456789HHeLiBeBCNOFNeNaMgAlSiPSClArKCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoRuRhPdAgCdInSnSbTeIXeCsBaLaCePrNdSmEuGdTbDyHoErTmYbLuHfTaWReOsIrPtAuHgTlPbBiThPaU]",0) then
guictrlsetdata($input1,StringRegExpReplace($str,"[^0123456789HHeLiBeBCNOFNeNaMgAlSiPSClArKCaScTiVCrMnFeCoNiCuZnGaGeAsSeBrKrRbSrYZrNbMoRuRhPdAgCdInSnSbTeIXeCsBaLaCePrNdSmEuGdTbDyHoErTmYbLuHfTaWReOsIrPtAuHgTlPbBiThPaU]",""))
MsgBox(0,"caractère incorect","vous avez saisie un élément ou un caractère invalide, s'il existe vraiment, la base de donnée n'est pas capable de fournir une masse molaire (élément instable par exemple)")
return 0
;on supprime les caractères indésirables en les recherchant avec une expression régulière puis on averti l'utilisateur de son erreur
EndIf
$ret=0
$t=stringregexp($str,"[A-Z][a-z]|[A-Z]",3) ; on recherche les atomes représenté par une lettre majuscule (H par exemple) ou bien une majuscule et une minuscule (Mn par exemple), l'expression régulière cherche d'abord deux lettre à la fois pour ne pas créer d'ambiguité
if _arraytostring($t,"+$")<>"" then $reg="$"&_arraytostring($t,"+$")&"+" ; on ajoute ceci à l'expression
$t=StringRegExp($str,"[A-Z][a-z][0-9]+",3) ;puis on fait la même chose avec les atomes coéficianté (H2 par exemple)
if StringRegExpReplace(_arraytostring($t,""),"([0-9]+)","*($1-1)+$")<>"" then $reg&="$"&StringRegExpReplace(_arraytostring($t,""),"([0-9]+)","*($1-1)+$")&"+"
;vu qu'ils sont déjà compté pluys haut, on retranche un au coéficiant (l'expression est plus complexe mais l'utilisateur ne le sait pas)
$t=StringRegExp($str,"[A-Z][0-9]+",3) ;idem pour les atomes à deux lettres coéficianté (on les a séparer cette fois pour des raison pratique lors du réarengement de l'expression)
if StringRegExpReplace(_arraytostring($t,""),"([0-9]+)","*($1-1)+$")<>"" then $reg&="$"&StringRegExpReplace(_arraytostring($t,""),"([0-9]+)","*($1-1)+$")
while not (StringIsAlNum(stringright($reg,1)) or stringright($reg,1)=")" or $reg="")
$reg=stringtrimright($reg,1) ;on supprime les caractères indésirable
WEnd
GUICtrlSetData($input2,execute($reg)) ; puis on execute l'expression qui est de la forme $Mn + $O + $O*(4-1) pour retourner une valeur
; dans ce script on utilise des expression régulière, parfois de manière intenpestive mais uniquement dans le but de bien montre son fonctionnement
EndFunc
un exemple de frl:
Code : Tout sélectionner
[gaz parfait]
formule=P=N*8.314472*T/V|V=N*8.314472*T/P|N=P*V/(8.314472*T)|T=P*V/(8.314472*N)
varlist=PVNT