Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » First time with upp
First time with upp [message #35023] Thu, 29 December 2011 19:27 Go to next message
idkfa46 is currently offline  idkfa46
Messages: 155
Registered: December 2011
Experienced Member
hi guys,
this is my first time on upp, i was trying to build a little program to understand how upp works but i have some problems atm.

The simply program "prova2" just have to take take 2 numbers and return the sum but something is wrong...

this is my code:
main.cpp
#include "prova2.h"

prova2::prova2()
{
	CtrlLayout(*this, "Window title");
}

int prova2::calcolo(int x, int y)
{
	int somma;
	somma = x+y;
	return somma;	
}	

GUI_APP_MAIN
{
	prova2().Run();
}


prova2.h

#ifndef _prova2_prova2_h
#define _prova2_prova2_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <prova2/prova2.lay>
#include <CtrlCore/lay.h>



class prova2 : public Withprova2Layout<TopWindow> {

	int calcolo(int x, int y);	
	
public:
	typedef prova2 CLASSNAME;
	prova2();
};

#endif



prova2.lay
LAYOUT(prova2Layout, 268, 140)
	ITEM(EditInt, x, LeftPosZ(52, 64).TopPosZ(24, 19))
	ITEM(EditInt, y, LeftPosZ(188, 64).TopPosZ(24, 19))
	ITEM(Label, dv___2, SetLabel(t_("X =")).LeftPosZ(16, 33).TopPosZ(24, 21))
	ITEM(Label, dv___3, SetLabel(t_("Y =")).LeftPosZ(152, 33).TopPosZ(24, 21))
	ITEM(Label, somma, LeftPosZ(80, 172).TopPosZ(52, 24))
	ITEM(Label, dv___5, SetLabel(t_("Somma =")).LeftPosZ(16, 56).TopPosZ(56, 21))
	ITEM(Button, calcola, SetLabel(t_("CALCOLA")).SetFont(StdFontZ(19).Bold()).LeftPosZ(16, 236).TopPosZ(88, 32))
END_LAYOUT


where is my epic fail ?!
how is possible to obtain the sum without typing the button "CALCOLA" ?

Thanks for ur help and your time
regards,
Matteo
Re: First time with upp [message #35024 is a reply to message #35023] Thu, 29 December 2011 20:15 Go to previous messageGo to next message
cb31_fr is currently offline  cb31_fr
Messages: 5
Registered: April 2007
Promising Member
Hi,

Your prova2.h and main.cpp modified.
The addition will be automatically done each time x or y is updated.


prova2.h :

#ifndef _prova2_prova2_h
#define _prova2_prova2_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <prova2/prova2.lay>
#include <CtrlCore/lay.h>



class prova2 : public Withprova2Layout<TopWindow> {
public:
	typedef prova2 CLASSNAME;
	prova2();

private:
	void calcolo();	
};

#endif



And main.cpp :

#include "prova2.h"

prova2::prova2()
{
	CtrlLayout(*this, "Window title");

	// you must add a callback on x or y fields update	
	x <<= THISBACK( calcolo) ;
	y <<= THISBACK( calcolo) ;
}

void prova2::calcolo()
{
	// You do the addition only if x and y are valid
	if( !( x.IsNullInstance() || y.IsNullInstance() ) )
	{
		// Here, you must get the value inserted in your x EditInt field (done with ~x)
		int xValue = ~x ;
	
		// And, you must also get the value inserted in your y EditInt field (done with ~y)
		int yValue = ~y ;
	
		// And now, you must update your somma Label field with the addition.
		// As somma is a Label, we must convert your result into text (done by Format)
		// and then, you update your field by the SetText method.
		somma.SetText( Format( "%d", xValue+yValue ) );
	}
	else
	{
		somma.SetText( "" ) ;
	}

	return ;	
}	

GUI_APP_MAIN
{
	prova2().Run();
}


Have fun with Upp.
Regards
Christian

Re: First time with upp [message #35032 is a reply to message #35023] Fri, 30 December 2011 15:25 Go to previous messageGo to next message
idkfa46 is currently offline  idkfa46
Messages: 155
Registered: December 2011
Experienced Member
oh thanks! now is better Very Happy
Re: First time with upp [message #35109 is a reply to message #35032] Thu, 12 January 2012 16:22 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
And a big welcome to my very first TimberStruct customer Very Happy

Max
Re: First time with upp [message #35113 is a reply to message #35109] Thu, 12 January 2012 21:39 Go to previous message
koldo is currently offline  koldo
Messages: 3356
Registered: August 2008
Senior Veteran
Smile

Best regards
IƱaki
Previous Topic: Accessing controls in layout within ArrayCtrl
Next Topic: MainMenu problem
Goto Forum:
  


Current Time: Sat Apr 20 17:22:29 CEST 2024

Total time taken to generate the page: 0.01849 seconds