Fórum Erro no código - URGENTE #460393
07/11/2013
0
Estou usando DbEdit s e CheckBox (ck8 ao ck16)
procedure TFClientes.btnCalcularClick(Sender: TObject);
Var Resultado1, Valor1, Valor2, Valor3 : Real;
Var Resultado2, Resultado3, Resultado4, Resultado5, Resultado6, Resultado7 :Real;
Var SubTotalServicos, SubTotalTaxas, Total :Real;
Var SomaCk8, SomaCk9, SomaCk10, SomaCk11, SomaCk12, SomaCk13, SomaCk14, SomaCk15, SomaCk16 :Real;
begin
Resultado1:= StrToFloat(DBEdit55.Text) * StrToFloat(txtValor1.Text);
Resultado2:= StrToFloat(DBEdit57.Text) * StrToFloat(txtValor2.Text);
Resultado3:= StrToFloat(DBEdit59.Text) * StrToFloat(txtValor3.Text);
Resultado4:= StrToFloat(DBEdit61.Text) * StrToFloat(txtValor4.Text);
Resultado5:= StrToFloat(DBEdit63.Text) * StrToFloat(txtValor5.Text);
Resultado6:= StrToFloat(DBEdit65.Text) * StrToFloat(txtValor6.Text);
Resultado7:= StrToFloat(DBEdit67.Text) * StrToFloat(txtValor7.Text);
SubTotalServicos := Resultado1 + Resultado2 + Resultado3 + Resultado4 + Resultado5 + Resultado6 + Resultado7;
if Ck8.Checked = true then
begin
SomaCk8 := strToFloat(DBValor8.Text);
end
else
SomaCk8 := 0;
if Ck9.Checked = true then
begin
SomaCk9 := strToFloat(DBValor9.Text);
end
else
SomaCk9 := 0;
if Ck10.Checked = true then
begin
SomaCk10 := strToFloat(DBValor10.Text);
end
else
SomaCk10 := 0;
if Ck11.Checked = true then
begin
SomaCk11 := strToFloat(DBValor11.Text);
end
else
SomaCk11 := 0;
if Ck12.Checked = true then
begin
SomaCk12 := strToFloat(DBValor12.Text);
end
else
SomaCk12 := 0;
if Ck13.Checked = true then
begin
SomaCk13 := strToFloat(DBValor13.Text);
end
else
SomaCk8 := 0;
if Ck14.Checked = true then
begin
SomaCk14 := strToFloat(DBValor14.Text);
end
else
SomaCk14 := 0;
if Ck15.Checked = true then
begin
SomaCk15 := strToFloat(DBValor15.Text);
end
else
SomaCk15 := 0;
if Ck16.Checked = true then
begin
SomaCk16 := strToFloat(DBValor16.Text);
end
else
SomaCk16 := 0;
SubTotalTaxas:= SomaCk8 + SomaCk9 + SomaCk10 + SomaCk11 + SomaCk12 + SomaCk13 + SomaCk14 + SomaCk15 + SomaCk16;
txtResultado.Text := FloatToStr(SubTotalServicos + SubTotalTaxas);
end;
Marcos Loyola
Curtir tópico
+ 0Posts
07/11/2013
Thiago Irrazabal
Resultado1:= StrToFloat(StringReplace(DBEdit55.Text, '.', '', [rfReaplceAll, rfIgnoreCase])) * StrToFloat(StringReplace(txtValor1.Text, '.', '', [rfReplaceAll, rfIgnoreCase]));
Att,
Thiago Irrazabal de Oliveira.
Gostei + 0
07/11/2013
Marcos Loyola
estão só com virgula 15,50 por ai vai
Gostei + 0
07/11/2013
Thiago Irrazabal
estão só com virgula 15,50 por ai vai
Se tu diz... enfim tu já debugou? abraço
Att,
Thiago Irrazabal de Oliveira.
Gostei + 0
07/11/2013
Vagner Almeida
Ficaria assim: Resultado := StrToFloatDef(Campo.Text, 0);
Outra opção é usar o FormatFloat(',0.00;', Campo.Text); - o retorno é uma String, por isso teria que converter para Float depois.
Ficaria assim: Resultado := StrToFloat( FormatFloat(',0.00;', Campo.Text) );
MAS a resposta de Thiago Irrazabal, acredito ser a mais correta. Porém, fica ai algumas informações a mais.
Espero ter ajudado...
Gostei + 0
08/11/2013
Samuel Santos
Não utilize o conteúdo do DBEdit.text para efetuar seus cálculos. Após o usuário efetuar a edição no campo, o conteúdo irá para o Dataset em que este está ligado:
- Resultado1:= Query1.FieldByName('CAMPOX').AsFloat * Query1.FieldByName('CAMPOX').AsFloat;
Outra coisa que gosto de usar é o tipo Double no lugar do Real: Var Resultado1, Valor1, Valor2, Valor3 : Double;
SSS
Gostei + 0
08/11/2013
Marcos Loyola
fiz da forma que Samuel passou Resultado1:= Query1.FieldByName('CAMPOX').AsFloat * Query1.FieldByName('CAMPOX').AsFloat;
funcionou blz
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)