Display a number in TGLabel widget

[size=150]Dear All happy new year!

My problem is the following:
I drew TGLabel widget.
I want to read in a file (.dat) a certain number of data and display this number in the widget Label.
but my program says that, there is an syntax error and I have several times checked the program and I do not understand why there is this error.
Can somebody help me to check my scrip to tell me what does not go well?

Thanks for your attention,

[code]#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TString.h>

#include “Riostream.h”

void histo();

class MyMainFrame : public TGMainFrame {

private:

TGLabel *fLabel515;

public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();

void DoLabel(nlines) ;

ClassDef(MyMainFrame, 0)

};

MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h): TGMainFrame(p, w, h)

{

this->SetLayoutBroken(kTRUE);

TGFont ufont; // will reflect user font changes
ufont = gClient->GetFont("-
-Arial-bold-r---24-------*");

TGGC *uGC; // will reflect user GC changes
// graphics context changes
GCValues_t vall515;
vall515.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
gClient->GetColorByName("#000000",vall515.fForeground);
gClient->GetColorByName("#c0c0c0",vall515.fBackground);
vall515.fFillStyle = kFillSolid;
vall515.fFont = ufont->GetFontHandle();
vall515.fGraphicsExposures = kFALSE;
uGC = gClient->GetGC(&vall515, kTRUE);

ULong_t ucolor; // will reflect user color changes
gClient->GetColorByName("#3399ff",ucolor);
TGLabel *fLabel515 = new TGLabel( this,“1000”,uGC->GetGC(),ufont->GetFontStruct(),kChildFrame,ucolor);
fLabel515->SetTextJustify(36);
fLabel515->SetMargins(0,0,0,0);
fLabel515->SetWrapLength(-1);
this->AddFrame(fLabel515, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
fLabel515->MoveResize(16,8,192,72);

this->SetMWMHints(kMWMDecorAll,
kMWMFuncAll,
kMWMInputModeless);
this->MapSubwindows();

this->Resize(this->GetDefaultSize());
this->MapWindow();
this->Resize(256,101);

histo();
}

void MyMainFrame::DoLabel(nlines)
{

cout<<“val =”<<nlines<<endl;
fLabel515->SetText(Form("%d",nlines));

this->Layout();

}

void histo( )
{
ifstream in;

in.open(“essai.dat”);

Float_t x;
Int_t nlines = 0;

TH1F *h1 = new TH1F(“h1”,“x distribution”,100,19000,21000);

while (1) {
in >> x ;
if (!in.good()) break;

  h1->Fill(x);
 
  nlines++;

}

in.close();

TCanvas *C1 = new TCanvas("1X ",“1X”,1);
h1 -> Draw();

MyMainFrame::DoLabel(nlines);
//above, the programme refuses to allow me to use “nlines” as argument. Why ?
}

void test1()
{
new MyMainFrame(0,100,100);

}[/code][/code][/size]

Hi,

You have not specified the type of ‘nlines’ parameter.

Cheers, Ilka

Hello Ilka !
Thanks to take the time to help me, I really appreciate your effort.
I tried to specify the type everywhere where it was necessary. now in the part above, I have this error:

What means that error ?

[code]void MyMainFrame::DoLabel(Int_t nlines)
{

cout<<“val =”<<nlines<<endl;

fLabel515->SetText(Form("%d",nlines));

this->Layout();

}[/code]

Hi,

I did not notice the following error before. In your constructor replace the lineTGLabel *fLabel515 = new TGLabel(this,"1000",uGC->GetGC(),ufont->GetFontStruct(),kChildFrame,ucolor); by fLabel515 = new TGLabel( this,"1000",uGC->GetGC(),ufont->GetFontStruct(),kChildFrame,ucolor);
Also, there is a method TGLabel::SetText(Int_t number), which accepts an integer number as a parameter. You could replacefLabel515->SetText(Form("%d",nlines));byfLabel515->SetText(nlines);After these minor changes your macro runs with no error.

Cheers, Ilka

Thank you,

I make all the change that you suggested me but it continues to say to me that there is

at the line

Perhaps the declaration that I made at the head of my program is false, but I do not see what is false

Hi,

Please find the macro test1.C attached and let me know do you get errors when running it.

Thank you, Ilka
test1.C (2.53 KB)

Perfect!
It runs very well and it is exactly what I want.
It remain to compare script that you sent me to my program to understand what did not runs in my program.
thank you once more. Excuse me to have disturbed you all the day with this problem.

No problem at all - I am glad to help.

Cheers, Ilka