Re: Simple function not working

new topic     » goto parent     » topic index » view thread      » older message » newer message

try this:

include pGUI.e  
  
Ihandle l1, l2, l3, t1, t2, h1, h2, h3, b1, v1, dlg  
  
function addfn(Ihandle /*b1*/) 
    IupSetStrAttribute(l3,"TITLE",sprint(IupGetDouble(t1,"VALUE")+IupGetDouble(t2,"VALUE"))) 
    return IUP_DEFAULT  
end function  
  
IupOpen()   
 
l1 = IupLabel("First value: ")  
t1 = IupText("EXPAND=YES")  
h1 = IupHbox({l1, IupLabel(), t1}) 
  
l2 = IupLabel("Second value: ")  
t2 = IupText("EXPAND=YES")  
h2 = IupHbox({l2, IupLabel(), t2})  
  
b1 = IupButton("Calculate", Icallback("addfn")) 
  
l3 = IupLabel("Read sum here.")  
h3 = IupHbox({b1, IupLabel("->"), l3})  
  
v1 = IupVbox({IupLabel(), h1,IupLabel(),h2,IupLabel(), h3})  
  
dlg = IupDialog(v1, "TITLE=Test, MARGIN=10x10, PADDING=5x5")  
  
IupShow(dlg)   
IupMainLoop()   
IupClose()  

PS: Rather than value(), unless you need whole sequences I would normally recommend scanf(), to_integer(), or to_number(), but IupGetInt/IupGetFloat/IupGetDouble also do the job here.
Attributes such as MARGIN and PADDING are often inheritable, unless explicitly marked otherwise, so you only have to specify them once. One day I'll finish my layout editor...
I've known for some time that addfn() somehow works, but I could never, ever, really bring myself to recommend that.

PPS: For the record, I get

        setText(l3, sprintf(append("", value(getText(t1)) + value(getText(t2).. 
                    ^ missing non-defaulted parameter [args] 

in other words the same as sprintf("123") [I just used sprint() instead above], and obviously getText/setText are arwen/win32lib, not pGUI.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu