Loop Repetindo varios itens

Delphi

22/08/2005

Bom gente eu to usando esse loop mas ele esta repetindo varias vezes os valores,esta pegando valores que nao era pra pegar...gostaria que vcs dessem uma olhada nele pra ver o que tem de errado com ele...
valeu galera!

 while not QryIncidencia.Eof do
  begin
 if QryIncidenciaCOD_VENDEDOR.value= QryFuncionariosCod_VENDEDOR.Value then
 {Query1COD_COLABORADOR.VALUE}
  begin
  if QryIncidenciaTIPO.Value=´¬´then
   begin
  QryLancamento.Insert;
  QryLancamentoHistorico.Value:=QryIncidenciaDESCRICAO.Value;
  QryLancamentoValor.Value:=QryIncidenciaValor.Value * QryFuncionariosSalario_REGISTRO.Value div 100;
  QryLancamentoTipo.Value:=QryIncidenciaNatureza.Value;
  QryLancamentoCodFunc.Value:=QryFuncionariosCod_Vendedor.Value;
  QryLancamentoDATA.Value:=Date;
  QryLancamento.post;
  end
  else
   if QryIncidenciaTIPO.VALUE=´V´ then
   BEGIN
 QryLancamento.Insert;
 QryLancamentoDATA.Value:=Date;
 QryLancamentoValor.Value:=QryIncidenciaValor.Value;
 QryLancamentoTipo.Value:=QryIncidenciaNatureza.Value;
 QryLancamentoCodFunc.Value:=QryFuncionariosCod_Vendedor.Value;
 QryLancamentoHistorico.Value:=QryIncidenciaDESCRICAO.Value;
 QryLancamento.Post;
 end
 else
 QryLancamento.Open;
 QryLancamento.Insert;
 QryLancamentoDATA.Value:=Date;
 QryLancamentoHistorico.Value:=´VALOR SALARIO´;
 QryLancamentoValor.Value:=QryFuncionariosVALOR_SALARIO.Value;
 QryLancamentoTipo.Value:=QryIncidenciaNatureza.Value;
 QryLancamentoCodFunc.Value:=QryFuncionariosCod_Vendedor.Value;
 QryLancamento.Post;
 QryLancamento.Insert;
 QryLancamentoHistorico.Value:=´SALARIO FAMILIA´;
 QryLancamentoDATA.Value:=Date;
 QryLancamentoValor.Value:=QryFuncionariosVALOR_SALARIO_FAMILIA.Value * QryFuncionariosQuant_Sal_Familia.Value;
 QryLancamentoTipo.Value:=QryIncidenciaNatureza.Value;
 QryLancamentoCodFunc.Value:=QryFuncionariosCod_Vendedor.Value;

 {if QryLancamentoTIPO.Value=´E´ then
  begin
   QryLancamento.Open;
   QryLancamento.Insert;
   Total_prov:=Total_prov+QryLancamentoValor.Value;
   QryLancamentoTotal_prov.value:=Total_prov;
   QryLancamento.Post;
   end
   else
   begin
   QryLancamento.Open;
   QryLancamento.Insert;
 if QryLancamentoTIPO.Value=´S´then
  begin
  Total_inc:=Total_inc+QryLancamentoValor.Value;
  QryLancamentoTotal_inc.Value:=Total_inc;}

  QryLancamento.post;
  QryIncidencia.Next;
  QryLancamento.APPLYUPDATES;

  end;
  end;



L3gion4rio

L3gion4rio

Curtidas 0

Respostas

Michael

Michael

22/08/2005

Colega,

Neste bloco:

 else
 QryLancamento.Open;
 QryLancamento.Insert;
 QryLancamentoDATA.Value:=Date;
 QryLancamentoHistorico.Value:=´VALOR SALARIO´;
 QryLancamentoValor.Value:=QryFuncionariosVALOR_SALARIO.Value;
 QryLancamentoTipo.Value:=QryIncidenciaNatureza.Value;
 QryLancamentoCodFunc.Value:=QryFuncionariosCod_Vendedor.Value;
 QryLancamento.Post;
 QryLancamento.Insert;
 QryLancamentoHistorico.Value:=´SALARIO FAMILIA´;
 QryLancamentoDATA.Value:=Date;
 QryLancamentoValor.Value:=QryFuncionariosVALOR_SALARIO_FAMILIA.Value * QryFuncionariosQuant_Sal_Familia.Value;
 QryLancamentoTipo.Value:=QryIncidenciaNatureza.Value;
 QryLancamentoCodFunc.Value:=QryFuncionariosCod_Vendedor.Value; 


Os comandos após o [b:0b2dd2e364]else [/b:0b2dd2e364]não está entre um par [b:0b2dd2e364]begin-end[/b:0b2dd2e364]. Ou seja, apenas a primeira linha após ele será executada condicionalmente. As outros serão executadas sempre, em cada passada do loop.

Verifique também todos os outros [b:0b2dd2e364]begins-ends[/b:0b2dd2e364], pois acho que vc copiou o código de forma incorreta para cá.

[]´s


GOSTEI 0
Rjun

Rjun

22/08/2005

Dei uma arrumada no seu código e retirei a parte que você deixou em comentário. Veja se resolve seu problema.

while (not qryIncidencia.Eof) do
begin
  if (qryIncidencia.FieldByName(´COD_VENDEDOR´).Value = qryFuncionarios.FieldByName(´Cod_VENDEDOR´).Value) then
  begin
    if qryIncidencia.FieldByName(´TIPO´).Value = ´¬´ then
    begin
      qryLancamento.Insert;
      qryLancamento.FieldByName(´Historico´).Value := qryIncidenciaDESCRICAO.Value;
      qryLancamento.FieldByName(´Valor´).Value := qryIncidenciaValor.Value * qryFuncionariosSalario_REGISTRO.Value div 100;
      qryLancamento.FieldByName(´Tipo´).Value := qryIncidenciaNatureza.Value;
      qryLancamento.FieldByName(´CodFunc´).Value := qryFuncionariosCod_Vendedor.Value;
      qryLancamento.FieldByName(´DATA´).Value := Date;
      qryLancamento.Post;
    end
    else if (qryIncidencia.FieldByName(´TIPO´).VALUE = ´V´) then
    begin
      qryLancamento.Insert;
      qryLancamento.FieldByName(´DATA´).Value := Date;
      qryLancamento.FieldByName(´Valor´).Value := QryIncidenciaValor.Value;
      qryLancamento.FieldByName(´Tipo´).Value := QryIncidenciaNatureza.Value;
      qryLancamento.FieldByName(´CodFunc´).Value := QryFuncionariosCod_Vendedor.Value;
      qryLancamento.FieldByName(´Historico´).Value := QryIncidenciaDESCRICAO.Value;
      qryLancamento.Post;
    end
    else
    begin
      qryLancamento.Open;
      qryLancamento.Insert;
      qryLancamento.FieldByName(´DATA´).Value := Date;
      qryLancamento.FieldByName(´Historico´).Value := ´VALOR SALARIO´;
      qryLancamento.FieldByName(´Valor´).Value := qryFuncionariosVALOR_SALARIO.Value;
      qryLancamento.FieldByName(´Tipo´).Value := qryIncidenciaNatureza.Value;
      qryLancamento.FieldByName(´CodFunc´).Value := qryFuncionariosCod_Vendedor.Value;
      qryLancamento.Post;

      qryLancamento.Insert;
      qryLancamento.FieldByName(´Historico´).Value := ´SALARIO FAMILIA´;
      qryLancamento.FieldByName(´DATA´).Value := Date;
      qryLancamento.FieldByName(´Valor´).Value := qryFuncionariosVALOR_SALARIO_FAMILIA.Value * qryFuncionariosQuant_Sal_Familia.Value;
      qryLancamento.FieldByName(´Tipo´).Value := qryIncidenciaNatureza.Value;
      qryLancamento.FieldByName(´CodFunc´).Value := qryFuncionariosCod_Vendedor.Value;
      qryLancamento.Post;
    end;

    qryIncidencia.Next;
    qryLancamento.ApplyUpdates;
  end;
end;



GOSTEI 0
L3gion4rio

L3gion4rio

22/08/2005

Valeu Michael e RJun, deu certo aqui eu usei o codigo que o Colega Rjun passou corrigido deu certinho... valeu mesmo pela atencao, precisando e eu podendo ajudar podem contar comigo ta ok...valeu! abração pra vocês.


GOSTEI 0
POSTAR