require("ui","cas","table","io") function initvar() init={name="",cd={{name="",value1="",value2=""}}} str_input_nhom="Catelogy:" Input_unit_name="Unit name:" Input_unit_value="Unit value:" addcat="+Catelogy" addunit="+Unit" texit="Exit" strcd="Conv" end function read() fi = io.file("main/convsave") if(fi:exists()) then fi:open("r") data=fi:read(1) fi:close() else data={} data[1]=init end end function write() fi = io.file("main/convsave") if not fi:exists() then fi:create("data","ConvData") end fi:open("w") fi:write(data) fi:close() end function addnhom() ui.stop() win:show(false) cons:setposition(0,0) local ten=input(str_input_nhom) data[#data]={name=ten,cd={{name="",value1="",value2=""}}} table.sort(data,function(a,b) if a.name<b.name then return true end end) i=1 while(i<#data) do if(data[i].name==data[i+1].name) then table.remove(data,i) else i=i+1 end end data[#data+1]=init end function addft(i) ui.stop() win:show(false) cons:setposition(0,0) local ten,val1,val2=input(Input_unit_name),input(Input_unit_value.."(*)"),input(Input_unit_value.."(+)") data[i].cd[#data[i].cd]={name=ten,value1=val1,value2=val2} table.sort(data[i].cd,function(a,b) if a.name<b.name then return true end end) ki=1 while(ki<#data[i].cd) do if(data[i].cd[ki].name==data[i].cd[ki+1].name) then table.remove(data[i].cd,ki) else ki=ki+1 end end data[i].cd[#data[i].cd+1]={name="",value1="",value2=""} end function conv() initvar() read() local sel,sas,ssa=1,1,1 win = ui.window{name="main",x=0,y=0,width=160,height=100, frame="thick",scroll="v"} m = ui.menu() m:add{type="button", text=addcat, _action=function() addnhom() end} m:add{type="button", text=addunit, _action=function() if #data>1 then addft(sel) end end} m:add{type="button", text=texit, _action=function() running=false ui.stop() end} win:add(m) value=ui.textedit{x=10,y=10,width=130,height=16,frame ="thin",align="center",parent=win} local do_conv=ui.button{x=30,y=60,width=100,parent=win,text=strcd,_clicked=function() local calc=cas("a2*(x-b1)/a1+b2|x="..cas(value:gettext()).."|a1="..cas(data[sel].cd[sas].value1).."|b1="..cas(data[sel].cd[sas].value2).."|a2="..cas(data[sel].cd[ssa].value1).."|b2="..cas(data[sel].cd[ssa].value2)) print(value:gettext().." "..data[sel].cd[sas].name.." = "..calc.." "..data[sel].cd[ssa].name.."\n ~"..cas.approx(calc).." "..data[sel].cd[ssa].name) end} running=true cons = ui.getwin("Console") while running do cons:setposition(0,105) cons:setsize(160,100) local dfrom=ui.combobox{x=10,y=45,width=57,height=10*#data[1].cd,parent=win,scroll="auto",_selected=function(I,T) sas=T end} local dto=ui.combobox{x=67,y=45,width=57,height=10*#data[1].cd,parent=win,_selected=function(I,T) ssa=T end} local nhom=ui.combobox{x=10,y=30,width=114,height=10*#data,parent=win,_selected=functi on(II,T) sel=T ui.stop() end} local do_delt=ui.button{x=130,y=44,width=10,parent=win,text="x",_clicked=function() if #data[sel].cd~=1 then table.remove(data[sel].cd,ssa) ssa=1 ui.stop() end end} local do_deln=ui.button{x=130,y=29,width=10,parent=win,text="x",_clicked=function() if #data~=1 then table.remove(data,sel) sel=1 ui.stop() end end} for i=1,#data-1 do nhom:addstring(data[i].name) end if #data[sel].cd~=1 then for i=1,#data[sel].cd-1 do dfrom:addstring(data[sel].cd[i].name) dto:addstring(data[sel].cd[i].name) end sas,ssa=1,1 dfrom:setselected(1) dto:setselected(1) end if #data>1 then nhom:setselected(sel) end win:show() ui.start() end win:show(false) cons:setposition(0,0) cons:setsize(160,215) write() end export{conv=conv}
use conv() to call the prog, I made this for only 7 mins and didnt test a lot, fell free to edit it.