Pon un ejemplo de la línea, porque no entiendo bien cual es el formato de cada una.
Si por ejemplo fuera así:
Código:
01/01/2009,123.98
02/01/2009,21.32
...
puedes hacerlo de la siguiente manera:
- Lees todo dentro de un TStringList
(SList.LoadFromFile(archivo))
- Te metes dentro de un bucle leyendo cada linea
(for i := 0 to SList.Lines.Count -1)
- De cada línea lees las partes
(
fecha := StringToDateTime(copy(SList.Lines[i],1,10))
dato := StrToInt(copy(SList.Lines[i],12,10 {longitud del campo}))
)
- Con un if verificas si la fecha está dentro del rango a promediar
(if ((fecha>=DesdeFecha) and (fecha<=HastaFecha)) then)
Código Delphi
[-]
SList := TStringList.Create;
try
SList.LoadFromFile(archivo);
for i := 0 to SList.Lines.Count -1 do
begin
fecha := StringToDateTime(copy(SList.Lines[i],1,10))
dato := StrToInt(copy(SList.Lines[i],12,10 ))
if ((fecha>=DesdeFecha) and (fecha<=HastaFecha)) then
begin
Inc(cantidad);
Suma := Suma + Dato;
end;
end;
Promedio := Suma / cantidad;
finally
SList.Free;
end;