Einzelnen Beitrag anzeigen

Hellraizer

Registriert seit: 18. Dez 2008
Ort: NRW
28 Beiträge
 
Delphi 2007 Professional
 
#1

Berechnungsfehler aus Stringgriddaten

  Alt 5. Jan 2009, 17:32
Hallo,
habe ein Problem
ist ne ganz harte nuss

zuerst der Quelltext:

Delphi-Quellcode:
unit Paketdienst1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Grids, math;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Memo1: TMemo;
    StringGrid1: TStringGrid;
    BitBtn1: TBitBtn;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
stringgrid1.cells[0,0]:='PLZ';
stringgrid1.cells[1,0]:='Gewicht (kg)';
stringgrid1.cells[2,0]:='Länge (cm)';
stringgrid1.cells[3,0]:='Breite (cm)';
stringgrid1.cells[4,0]:='Höhe (cm)';
memo1.Text:='';
end;

procedure TForm1.Button1Click(Sender: TObject);
var z:integer;
begin
randomize;
for z:=1 to 1000 do
begin
  stringgrid1.Cells[0,z]:=formatfloat('00000', randomrange (1000, 99999));
  stringgrid1.Cells[1,z]:=inttostr (randomrange (1, 50));
  stringgrid1.Cells[2,z]:=inttostr (randomrange (1, 120));
  stringgrid1.Cells[3,z]:=inttostr (randomrange (1, 120));
  stringgrid1.Cells[4,z]:=inttostr (randomrange (1, 120));
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var z:integer;
begin
edit1.clear;
edit2.Clear;
for z := 1 to stringgrid1.rowcount - 1 do
stringGrid1.cells[0,z]:=('');
for z := 1 to stringgrid1.rowcount - 1 do
stringGrid1.cells[1,z]:=('');
for z := 1 to stringgrid1.rowcount - 1 do
stringGrid1.cells[2,z]:=('');
for z := 1 to stringgrid1.rowcount - 1 do
stringgrid1.cells[3,z]:=('');
for z := 1 to stringgrid1.rowcount - 1 do
stringGrid1.cells[4,z]:=('');
for z := 1 to stringgrid1.rowcount - 1 do
stringGrid1.cells[5,z]:=('');
memo1.clear;
stringgrid1.row:=1;
stringgrid1.col:=0;
stringgrid1.setfocus;
end;

procedure TForm1.Button2Click(Sender: TObject);
type tdatensatz=record gewicht, volumen:real; pakete, fahrzeuge: integer; end;
var plz: array[0..9] of tdatensatz;
    mg, mv: real;
    pl, p, x: integer; // mg=maximal_gewicht, mv=maximal_volumen, PLZ=PLZGebiet, pl=PLZ(HilfsVar), p=Postleitzahlgebit(HilfsVar), x=Zählvar(HilfsVar)
    g, l, b, h, v:Real; //g=gewicht, l=länge, b=breite, h=höhe, v=volumen


begin
memo1.Clear;
  if (edit1.Text='') or (edit2.text='') then
    begin
     showmessage ('Bitte vollstängige Eingaben');
     exit;
    end;
  if (strtoint(edit1.text)<=0) or (strtoint(edit2.text)<=0) then
    begin
     showmessage ('Bitte vollstängige und korrekte Eingaben');
     exit;
    end;
  for p:=0 to 9 do
   begin
     plz[p].gewicht:=0;
     plz[p].volumen:=0;
     plz[p].fahrzeuge:=0;
     plz[p].pakete:=0;
   end;
  mg:=strtofloatdef(edit1.text,-1)*1000;
  mv:=strtofloatdef(edit2.Text,-1)*1000000;
  if (mg<0) or (mv<0) then
    begin
     showmessage ('Bitte vollstängige und korrekte Eingaben');
     exit;
    end
  else
  begin
   for x:=1 to 1000 do
      begin
       pl:=strtointdef(stringgrid1.Cells[0,x],0);
       g:=strtofloatdef(stringgrid1.Cells[1,x],0);
       l:=strtofloatdef(stringgrid1.Cells[2,x],0);
       b:=strtofloatdef(stringgrid1.Cells[2,x],0);
       h:=strtofloatdef(stringgrid1.Cells[2,x],0);
       v:=h*b*l;
       if (pl>=1000) and (pl<=99999) and (g>0) and (v>0) then
         begin
           p:=pl div 10000;
           plz[p].gewicht:=plz[p].gewicht+g;
           plz[p].volumen:=plz[p].volumen+v;
           plz[p].pakete:=plz[p].pakete+1;
         end;
       end;
   for p:=0 to 9 do
      with plz[p] do
         fahrzeuge:=max (ceil (g/mg), ceil (v/mv));
   for p:=0 to 9 do
      with plz[p] do
         memo1.lines.add ('PLZ-Gebiet'+inttostr(p)+': '+
         inttostr(fahrzeuge)+'Fahrzeug(e), '+
         inttostr(pakete)+' Pakete');
  end
end;





end.



und zwar geht es darum das ich aus dem Stringgrid die Daten entnehme und damit rechne um die Anzahl der benötigten Fahrzeuge pro PLZ-Gebiet
(dabei wird jede PLZ durch 10.000 geteilt und dann durch die anfangsziffer einer gruppe zugeordnet, es gibt als gruppen von 0-9.
die anzahl der fahrzeuge wird definiert durch das volumen der pakete in abhängigkeit zum fahrzeug und dem gewicht der pakete zum fahrzeug.

Ich hoffe es kann wer was damit anfang und mir helfen. is vermutlich nur ein kleiner fehler, aber ich sitze schon stunden dran den zu finden -.-''

LG Kevin
  Mit Zitat antworten Zitat