après plusieurs tentatives qui se sont soldées par un échec je m'avoue vaincu mon code n'accepte pas le moins de cette touche . le programme considère que si je n'ai rien saisi quand j'utilises la touche . je sais que le problème vient des tonumber( j'ai essayé avec math.eval( ça pose un autre souci j'ai ce message :
attempt to perform arithmetic on local 'dr1' (a nil value)
voici le code : pas de commentaire sur mon code bizarre
- Code: Tout sélectionner
function on.construction()
TB = D2Editor.newRichText()
TB:setFontSize(8) TB:setReadOnly(true) TB:resize(199,110) TB:move(120,0) TB:setBorderColor(500) TB:setBorder(1)
TB1 = D2Editor.newRichText()
TB1:setFontSize(8) TB1:setReadOnly(true) TB1:resize(320,60) TB1:move(0,160)
editor = D2Editor.newRichText() editor:createMathBox() editor:resize(40,25) editor:move(40,2)
editor1 = D2Editor.newRichText() editor1:createMathBox() editor1:resize(40,25) editor1:move(40,28)
editor2 = D2Editor.newRichText() editor2:createMathBox() editor2:resize(100,30) editor2:move(0,75)
editor:registerFilter({tabKey = function() editor1:setFocus() end, enterKey = function() editor1:setFocus() end})
editor1:registerFilter({tabKey = function() editor2:setFocus() end, enterKey = function() editor2:setFocus() end})
editor2:registerFilter({tabKey = function() editor:setFocus() end , enterKey = function() traitement() end})
end
function on.getFocus()
editor:setFocus()
end
function on.paint(gc)
gc:setFont("sansserif","b",9)
gc:drawString("θ (°C) : ",1,2)
gc:drawString("Φ (%) : ",1,27)
gc:drawString("r (kge/kgas) : ",1,55)
gc:setColorRGB(255, 5, 8)
gc:setFont("sansserif","b",9)
gc:drawString("programme : psychro " , 90,130)
TB1:setExpression("\\chem { le programme donne les données du diagramme psychrometrie } \\chem { entrez 2 des 3 paramètres demandés}")
end
function traitement()
local e,f,g,d,ta,fi,t,ps,h,v,dr,dr1,dr2
e = editor:getExpression()
f = editor1:getExpression()
g = editor2:getExpression()
ta = string.gsub(string.gsub(e,"\\0el {",""),"}","") ta = tonumber(ta)
fi = string.gsub(string.gsub(f,"\\0el {",""),"}","") fi = tonumber(fi)
dr = string.gsub(string.gsub(g,"\\0el {",""),"}","") dr = tonumber(dr)
if ta == nil then
for i= -10, 40,0.01 do
t = i+273.15
dr2 = math.floor(dr*10^6)/10^6
dr1 = ((2.2417189023644*10^(19)*fi)/(math.exp(((6864.273257562)/(t)))*t^(5.2790907450839)-3.6040496822578*10^(19)*fi))
dr1 = math.floor(dr1*10^6)/10^6
if dr1 >= dr2 and i >= -10 then ta = i break end
end
end
t= ta+273.15
ps = ((3.6509023281268*10^(26)*math.exp(((-6864.273257562)/(t)))*(((1)/(t)))^(0.2790907450839))/(t^(5)))
if fi == nil then fi=((100*((dr)/(dr+((18)/(29))))*1.013*10^(5))/(ps)) end
if dr == nil then dr = ((2.2417189023644*10^(19)*fi)/(math.exp(((6864.273257562)/(t)))*t^(5.2790907450839)-3.6040496822578*10^(19)*fi)) end
h = 1.006*ta+dr*(1.84*ta+2501.6)
v = ((8.3145*t)/(1.013*10^(5)))*(((1)/(18))*dr+((1)/(29)))*10^(3)
r = " \\chem {θ = "..ta.." °C} \\chem {Φ = "..fi.." %} \\chem { h = "..h.." kJ/kgas} \\chem { r = "..dr.." kge/kgas} \\chem {v = "..v.." m^3/kg}"
TB:setExpression(r)
end
on m'avait proposé ça :
- Code: Tout sélectionner
function convertFromTI(str)
return str:gsub(string.uchar(0xF000), "e"):gsub("−","-")
end
j'au pas trop compris comment ça marchait
j'ai l'habitude d'appuyer sur auriez-vous une solution? merci d'avance