Ver Mensaje Individual
  #4  
Antiguo 22-02-2008
[maeyanes] maeyanes is offline
Capo de los Capos
 
Registrado: may 2003
Ubicación: Campeche, México
Posts: 2.732
Reputación: 24
maeyanes Va por buen camino
Hola...

Tienes varias opciones... usar un arreglo, o un TList... o hasta un TStringList:

O puedes copiar la lista a otra nueva y ordenarla y luego contar mientras no cambie el número:

Código Delphi [-]
var
  TempList: TStringList;
  OutPutList: TStringList;
  CurrentNumber: string;
  CurrentNumberCount: Integer;
  I: Integer;

begin
  TempList := TStringList.Create;
  // Copiamos la lista del TListBox a una temporal
  TempList.Assign(ListBox1.Items);
  // Ordenamos la lista para hacer más fácil el conteo
  TempList.Sort;  
  OutPutList := TStringList.Create;
  // Inicializamos la variable para obtener el primer número
  CurrentNumber := '';
  for I := 0 to Pred(TempList.Count) do
  begin
    // Si hay cambio de número, guardamos el total de ocurrencias y seguimos con el otro numero
    if CurrentNumber <> TempList[i] then
    begin
      if CurrentNumber <> '' then
        OutPutList.Add(Format('Del número %s hay %d repeticiones', [CurrentNumber, CurrentNumberCount]);
      CurrentNumber := TempList[i];
      CurrentNumberCount := 1
    end
    else
      Inc(CurrentNumberCount)
  end
end;

Este código lo hice al aire y no está probado, por lo que podría tener errores; pero te podría dar una idea de como hacerlo...



Saludos...
Responder Con Cita