FormatFloat

Delphi

09/05/2005

Olá, o código que eu coloquei abaixo a respeito do FormatFloat não está funcionado no evento BeforePrint do meu relatório, alguém saberia me ajudar???

procedure TFRel.qrpPesquisaBeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
var
total : double;
begin

qrlTitulo.Caption := ´Pesquisa Organizacional - ´ + FPesquisaOrg.cbFabrica.Text ;
qrl1.Caption := FPesquisaOrg.Frame11.Lb1.Caption;
qrl2.Caption := FPesquisaOrg.Frame11.lb2.Caption;

work.SQL.Text := ´Select count(*) as Contador ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrg.DB´´ +
´ where Q1 = ´ + QuotedStr(´M´) + ´and´ +
´ Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) ;
work.Open;

WORK1.SQL.Text := ´Select Total ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrgTotal.DB´´ +
´ where Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) ;
WORK1.Open;
showmessage(work1.fieldByNAME(´total´).AsString);
total := work.fieldByName(´Contador´).AsInteger / WORK1.fieldByName(´Total´).AsInteger * 100;
showmessage(formatFloat(´#.´, total));
qrl1Masculino.Caption := ´Masculino: ´ + FormatFloat(´.´, total);


Daia

Daia

Curtidas 0

Respostas

Rjun

Rjun

09/05/2005

Qual o resultado que esta aparecendo ?


GOSTEI 0
Daia

Daia

09/05/2005

está aparecendo 150, ao invés de aparecer 15


GOSTEI 0
Rjun

Rjun

09/05/2005

Utilize o Debug e veja o valor das variáveis [b:299302d58d]Contador[/b:299302d58d] e [b:299302d58d]Total[/b:299302d58d].


GOSTEI 0
Daia

Daia

09/05/2005

Contador = 3 e o Total = 2...


GOSTEI 0
Rjun

Rjun

09/05/2005

Contador = 3 e o Total = 2...

[b]3 / 2 * 100 = 150[b]

Se você quer calcular a porcentagem, então algo esta errado com sua tabela. Veja que o numero do contador teria que ser menor ou igual ao total.



GOSTEI 0
Daia

Daia

09/05/2005

na tabela esse contador conta os que são do sexo feminino- ´F´, conta os que são do sexo masculino- ´M´ e ainda os que estão em branco... lá na outra tabela onde gravo o total, acho q está o erro, pois lá ele grava só a fábrica e o total, acho que deveria ter mais um campo referenciando tb se for ´F´, ou ´M´ ou nulo. Será??.......


GOSTEI 0
Rjun

Rjun

09/05/2005

Como que está a estrutura de sua tabela ? Você se importa de postar a estrutura ? Se voce quiser saber o total, acho que bastava você dar um count na tabela dbpesquisaorg com o where da fabrica.

Você tem uma tabela que guarda somente o total de perguntas respondidas ? Não é necessário ter campos que guardam totalizações ja que elas podem ser obtidas através de um SQL.


GOSTEI 0
Daia

Daia

09/05/2005

Pensei em fazer isso daqui, para pegar o total:

´Select count(*) as Total ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrg.DB´´ +
´ where Q1 = ´ + QuotedStr(´M´) + ´or´ +
´ Q1 = ´ + QuotedStr(´F´) + ´or´ +
´ Q1 = ´ + QuotedStr(´ ´) + ´or´ +
´ Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) ;


GOSTEI 0
Rjun

Rjun

09/05/2005

Se os valores possiveis forem somente ´M´, ´F´ e ´ ´ então so o where para a fabrica é necessário.


GOSTEI 0
Daia

Daia

09/05/2005

só a fábrica não irá funcionar, pois tenho outros fábricas e tenho outras questões tb...
Por exemplo agora fiz por Filial1, não está dando certo, pois o resultado ficou:
M: 10¬ e Nulo: 10¬, mas na verdade tenho gravado apenas 1 pessoa do sexo M e uma que está em branco, ele deveria fazer M: 50¬ e Nulo: 50¬??


GOSTEI 0
Rjun

Rjun

09/05/2005

Coloque o trecho de código que você esta pegando os valores para calcular a porcentagem.


GOSTEI 0
Daia

Daia

09/05/2005

Tá aí...
procedure TFRel.qrpPesquisaBeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
var
total : double;
begin
total:=0;

qrlTitulo.Caption := ´Pesquisa Organizacional - ´ + FImpFab.cbFabrica.Text ;
qrl1.Caption := FPesquisaOrg.Frame11.Lb1.Caption;
qrl2.Caption := FPesquisaOrg.Frame11.lb2.Caption;
//se masculino
work.SQL.Text := ´Select count(*) as Contador ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrg.DB´´ +
´ where Q1 = ´ + QuotedStr(´M´) + ´and´ +
´ Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) ;
work.Open;

WORK1.SQL.Text := ´Select count(*) as Total ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrg.DB´´ +
´ where Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) + ´and´ +
´ Q1 = ´ + QuotedStr(´M´) + ´or´ +
´ Q1 = ´ + QuotedStr(´F´) + ´or´ +
´ Q1 = ´ + QuotedStr(´´);
WORK1.Open;
total := work.fieldByName(´Contador´).AsInteger / WORK1.fieldByName(´Total´).AsInteger * 100;
qrl1Masculino.Caption := ´Masculino: ´ + FormatFloat(´#.´, total) + ´ ¬´;

//se feminino
work.SQL.Text := ´Select count(*) as Contador ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrg.DB´´ +
´ where Q1 = ´ + QuotedStr(´F´) + ´and´ +
´ Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) ;
work.Open;

WORK1.SQL.Text := ´Select count(*) as Total ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrg.DB´´ +
´ where Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) + ´and´ +
´ Q1 = ´ + QuotedStr(´M´) + ´or´ +
´ Q1 = ´ + QuotedStr(´F´) + ´or´ +
´ Q1 = ´ + QuotedStr(´´);
WORK1.Open;

total := work.fieldByName(´Contador´).AsInteger / WORK1.fieldByName(´Total´).AsInteger * 100;
qrl1Feminino.Caption := ´Feminino: ´ + FormatFloat(´#.´, total) + ´ ¬´;

//se nulo
work.SQL.Text := ´Select count(*) as Contador ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrg.DB´´ +
´ where Q1 = ´ + QuotedStr(´´) + ´and´ +
´ Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) ;
work.Open;

WORK1.SQL.Text := ´Select count(*) as Total ´ +
´ from ´ +
´´C:\PesquisaOrg\dbPesquisaOrg.DB´´ +
´ where Fabrica = ´ + QuotedStr(FImpFab.cbFabrica.Text) + ´and´ +
´ Q1 = ´ + QuotedStr(´M´) + ´or´ +
´ Q1 = ´ + QuotedStr(´F´) + ´or´ +
´ Q1 = ´ + QuotedStr(´´);
WORK1.Open;

total := work.fieldByName(´Contador´).AsInteger / WORK1.fieldByName(´Total´).AsInteger * 100;
qrl1Nulo.Caption := ´Nulo: ´ + FormatFloat(´#.´, total) + ´ ¬´;


GOSTEI 0
Rjun

Rjun

09/05/2005

Tente fazer isso :

procedure TFRel.qrpPesquisaBeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean);
var
  total : double;
begin
  total:=0;

  qrlTitulo.Caption := ´Pesquisa Organizacional - ´ + FImpFab.cbFabrica.Text ;
  qrl1.Caption := FPesquisaOrg.Frame11.Lb1.Caption;
  qrl2.Caption := FPesquisaOrg.Frame11.lb2.Caption;

  //se masculino
  work.SQL.Text := ´Select count(*) as Contador from "C:\PesquisaOrg\dbPesquisaOrg.DB" where Q1 = ´´M´´ and Fabrica = :Fab´;
  work.ParamByName(´Fab´).Value := FImpFab.cbFabrica.Text;
  work.Open;

  work1.SQL.Text := ´Select count(*) as Total from "C:\PesquisaOrg\dbPesquisaOrg.DB" where Fabrica = :Fab´;
  work1.ParamByName(´Fab´).Value := FImpFab.cbFabrica.Text;
  work1.Open;

  total := work.fieldByName(´Contador´).AsInteger / work1.fieldByName(´Total´).AsInteger * 100;
  qrl1Masculino.Caption := ´Masculino: ´ + FormatFloat(´#.´, total) + ´ ¬´;

  {Coloque aqui o restante do código}
end;



GOSTEI 0
POSTAR