1. Simple function not working

I am trying to create a simple GUI program in Phix that adds numbers in 2 text fields:

include pGUI.e 
 
Ihandle t1, t2, t3, l1, l2, l3, b1, v1, h1, h2, h3, dlg 
 
IupOpen()  
 
function addfn() 
	setText(l3, sprintf(append("", value(getText(t1)) + value(getText(t2)))))  
	return IUP_DEFAULT 
end function 
 
l1=IupLabel("First value: ") 
t1 = IupText("EXPAND=YES") 
h1=IupHbox({l1, IupLabel(), t1}) 
IupSetAttribute(h1,"PADDING", "5x5") 
 
l2=IupLabel("Second value: ") 
t2 = IupText("EXPAND=YES") 
h2=IupHbox({l2, IupLabel(), t2}) 
IupSetAttribute(h2,"PADDING", "5x5") 
 
b1=IupButton("Calculate", Icallback("addfn")) 
IupSetAttribute(b1,"PADDING", "5x5") 
 
l3=IupLabel("Read sum here.") 
h3=IupHbox({b1, IupLabel("->"), l3}) 
IupSetAttribute(h3,"PADDING", "5x5") 
 
v1=IupVbox({IupLabel(), h1,IupLabel(),h2,IupLabel(), h3}) 
IupSetAttribute(v1,"PADDING", "5x5") 
 
dlg=IupDialog(v1) 
IupSetAttribute(dlg,"PADDING", "5x5") 
 
 
IupShow(dlg)  
IupMainLoop()  
IupClose() 

However, it is giving following errors:

..printf(append("", value(getText(t1)) + value(getText(t2)))))  
                                                            ^ missing parameters 
 setText(l3, sprintf(append("", value(getText(t1)) + value(getText(t2)))))  -.. 
                                                   ^Warning: sq_add() assumed 
 setText(l3, sprintf(append("", value(getText(t1)) + value(getText(t2)))))  -.. 
                                      ^Warning: forward call assumed 
 setText(l3, sprintf(append("", value(getText(t1)) + value(getText(t2)))))  -.. 
 ^Warning: forward call assumed 
Where is the problem and how can this be corrected? Thanks for your help.

new topic     » topic index » view message » categorize

2. Re: Simple function not working

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 message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu