Einzelnen Beitrag anzeigen

mat72

Registriert seit: 15. Mär 2012
35 Beiträge
 
#6

AW: Standardabweichung berechnen?

  Alt 31. Mär 2012, 19:48
Hallo,
ich lese jede Zahl via Textfeld ein und wandele sie mit StrToFloat in eine Zahl um.
Im Anhang mein Programm.
Delphi-Quellcode:
unit globallevelingacc;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, jpeg, ExtCtrls, shellapi, math;

type
  TForm11 = class(TForm)
    Image1: TImage;
    Label1: TLabel;
    MainMenu1: TMainMenu;
    MainMenu2: TMenuItem;
    Help1: TMenuItem;
    Exit1: TMenuItem;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Edit12: TEdit;
    Edit13: TEdit;
    Edit14: TEdit;
    Edit15: TEdit;
    Edit16: TEdit;
    Button1: TButton;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Button5: TButton;
    Label34: TLabel;
    procedure Exit1Click(Sender: TObject);
    procedure Help1Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Edit1Exit(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2Exit(Sender: TObject);
    procedure Edit2KeyPress(Sender: TObject; var Key: Char);
    procedure Edit3Exit(Sender: TObject);
    procedure Edit3KeyPress(Sender: TObject; var Key: Char);
    procedure Edit4Exit(Sender: TObject);
    procedure Edit4KeyPress(Sender: TObject; var Key: Char);
    procedure Edit5Exit(Sender: TObject);
    procedure Edit5KeyPress(Sender: TObject; var Key: Char);
    procedure Edit6Exit(Sender: TObject);
    procedure Edit6KeyPress(Sender: TObject; var Key: Char);
    procedure Edit7Exit(Sender: TObject);
    procedure Edit7KeyPress(Sender: TObject; var Key: Char);
    procedure Edit8Exit(Sender: TObject);
    procedure Edit8KeyPress(Sender: TObject; var Key: Char);
    procedure Edit9Exit(Sender: TObject);
    procedure Edit9KeyPress(Sender: TObject; var Key: Char);
    procedure Edit10Exit(Sender: TObject);
    procedure Edit10KeyPress(Sender: TObject; var Key: Char);
    procedure Edit11Exit(Sender: TObject);
    procedure Edit11KeyPress(Sender: TObject; var Key: Char);
    procedure Edit12Exit(Sender: TObject);
    procedure Edit12KeyPress(Sender: TObject; var Key: Char);
    procedure Edit13Exit(Sender: TObject);
    procedure Edit13KeyPress(Sender: TObject; var Key: Char);
    procedure Edit14Exit(Sender: TObject);
    procedure Edit14KeyPress(Sender: TObject; var Key: Char);
    procedure Edit15Exit(Sender: TObject);
    procedure Edit15KeyPress(Sender: TObject; var Key: Char);
    procedure Edit16Exit(Sender: TObject);
    procedure Edit16KeyPress(Sender: TObject; var Key: Char);
    procedure Button1Click(Sender: TObject);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form11: TForm11;
  x1,x2,x3,x4,x5,x6,x7,x8,y1,y2,y3,y4,y5,y6,y7,y8,ave_x,ave_y,x,y :extended;
implementation

{$R *.dfm}

procedure TForm11.Exit1Click(Sender: TObject);
begin
close();
end;

procedure TForm11.Help1Click(Sender: TObject);
begin
ShellExecute(Handle, 'open', '.\help\GlobalLevelingAccuracy.html', nil, nil, SW_SHOW); //hier wird die Hilfe aufgerufen
end;



procedure TForm11.Button5Click(Sender: TObject);
begin
close();
end;

procedure TForm11.Edit1Exit(Sender: TObject);
begin
    try
       x1:=StrToFloat(Edit1.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit1.Clear;
          Edit1.SetFocus;
    end;
end;

procedure TForm11.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit2.SetFocus;
end;

procedure TForm11.Edit2Exit(Sender: TObject);
begin
    try
       y1:=StrToFloat(Edit2.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit2.Clear;
          Edit2.SetFocus;
    end;
end;

procedure TForm11.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit3.SetFocus;
end;

procedure TForm11.Edit3Exit(Sender: TObject);
begin
    try
       x2:=StrToFloat(Edit3.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit3.Clear;
          Edit3.SetFocus;
    end;
end;

procedure TForm11.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit4.SetFocus;
end;

procedure TForm11.Edit4Exit(Sender: TObject);
begin
    try
       y2:=StrToFloat(Edit4.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit4.Clear;
          Edit4.SetFocus;
    end;
end;

procedure TForm11.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit5.SetFocus;
end;

procedure TForm11.Edit5Exit(Sender: TObject);
begin
    try
       x3:=StrToFloat(Edit5.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit5.Clear;
          Edit5.SetFocus;
    end;
end;

procedure TForm11.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit6.SetFocus;
end;

procedure TForm11.Edit6Exit(Sender: TObject);
begin
    try
       y3:=StrToFloat(Edit6.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit6.Clear;
          Edit6.SetFocus;
    end;
end;

procedure TForm11.Edit6KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit7.SetFocus;
end;

procedure TForm11.Edit7Exit(Sender: TObject);
begin
    try
       x4:=StrToFloat(Edit7.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit7.Clear;
          Edit7.SetFocus;
    end;
end;

procedure TForm11.Edit7KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit8.SetFocus;
end;

procedure TForm11.Edit8Exit(Sender: TObject);
begin
    try
       y4:=StrToFloat(Edit8.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit8.Clear;
          Edit8.SetFocus;
    end;
end;

procedure TForm11.Edit8KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit9.SetFocus;
end;

procedure TForm11.Edit9Exit(Sender: TObject);
begin
    try
       x5:=StrToFloat(Edit9.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit9.Clear;
          Edit9.SetFocus;
    end;
end;

procedure TForm11.Edit9KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit10.SetFocus;
end;

procedure TForm11.Edit10Exit(Sender: TObject);
begin
    try
       y5:=StrToFloat(Edit10.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit10.Clear;
          Edit10.SetFocus;
    end;
end;

procedure TForm11.Edit10KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit11.SetFocus;
end;

procedure TForm11.Edit11Exit(Sender: TObject);
begin
    try
       x6:=StrToFloat(Edit11.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit11.Clear;
          Edit11.SetFocus;
    end;
end;

procedure TForm11.Edit11KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit12.SetFocus;
end;

procedure TForm11.Edit12Exit(Sender: TObject);
begin
    try
       y6:=StrToFloat(Edit12.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit12.Clear;
          Edit12.SetFocus;
    end;
end;

procedure TForm11.Edit12KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit13.SetFocus;
end;

procedure TForm11.Edit13Exit(Sender: TObject);
begin
    try
       x7:=StrToFloat(Edit13.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit13.Clear;
          Edit13.SetFocus;
    end;
end;

procedure TForm11.Edit13KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit14.SetFocus;
end;

procedure TForm11.Edit14Exit(Sender: TObject);
begin
    try
       y7:=StrToFloat(Edit14.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit14.Clear;
          Edit14.SetFocus;
    end;
end;

procedure TForm11.Edit14KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit15.SetFocus;
end;

procedure TForm11.Edit15Exit(Sender: TObject);
begin
    try
       x8:=StrToFloat(Edit15.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit15.Clear;
          Edit15.SetFocus;
    end;
end;

procedure TForm11.Edit15KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit16.SetFocus;
end;

procedure TForm11.Edit16Exit(Sender: TObject);
begin
    try
       y8:=StrToFloat(Edit16.Text);
    except
          ShowMessage('Please enter only Numbers!');
          Edit16.Clear;
          Edit16.SetFocus;
    end;
end;

procedure TForm11.Edit16KeyPress(Sender: TObject; var Key: Char);
begin
 if (Key=#13)
    then
      Edit1.SetFocus;
end;

procedure TForm11.Button1Click(Sender: TObject);
begin
Label34.Caption := (' ');
//x:=stddev(x1,x2,x3,x4,x5,x6,x7,x8);
ave_x:=(x1+x2+x3+x4+x5+x6+x7+x8)/8;
ave_y:=(y1+y2+y3+y4+y5+y6+y7+y8)/8;
x:=3*(sqrt((1/8)*(((x1-ave_x)*(x1-ave_x))+((x2-ave_x)*(x2-ave_x))+((x3-ave_x)*(x3-ave_x))+((x4-ave_x)*(x4-ave_x))+((x5-ave_x)*(x5-ave_x))+((x6-ave_x)*(x6-ave_x))+((x7-ave_x)*(x7-ave_x))+((x8-ave_x)*(x8-ave_x)))));
y:=3*(sqrt((1/8)*(((y1-ave_y)*(y1-ave_y))+((y2-ave_y)*(y2-ave_y))+((y3-ave_y)*(y3-ave_y))+((y4-ave_y)*(y4-ave_y))+((y5-ave_y)*(y5-ave_y))+((y6-ave_y)*(y6-ave_y))+((y7-ave_y)*(y7-ave_y))+((y8-ave_y)*(y8-ave_y)))));
Label32.Caption := FloatToStrF(x, ffNumber, 8, 3);
Label33.Caption := FloatToStrF(y, ffNumber, 8, 3);
if (x>8) or (y>8) then
Label34.Caption := ('Out of Specification!')
end;

end.
Danke fuer eure Hilfe.
Gruss
Mat
  Mit Zitat antworten Zitat