![]() |
Re: Mittelwert von Myarray
Bist du sicher, das sich wirklich Integer-Werte im Array befinden?
|
Re: Mittelwert von Myarray
unit uZufall;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids; type TMyarray = Array [1..2,1..5] Of Integer; TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Button6: TButton; Button7: TButton; Edit3: TEdit; StringGrid1: TStringGrid; Memo1: TMemo; Edit1: TEdit; Edit2: TEdit; Edit4: TEdit; procedure FormCreate(Sender: TObject); procedure Button7Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button6Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; MyArray: TMyarray; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Button1.Caption := 'neu'; Button2.Caption := 'memo'; Button3.Caption := 'grid'; Button4.Caption := 'edit'; Button5.Caption := 'MWZeile'; Button6.Caption := 'MWKomplett'; Button7.Caption := 'close'; StringGrid1.ColCount := 4; StringGrid1.RowCount := 2; Memo1.Clear; Edit1.Visible := false; Edit2.Visible := false; Edit3.Visible := false; Edit4.Visible := false; Stringgrid1.Visible :=false; Memo1.Visible := false; end; procedure fuellen; var z,sp:integer; begin randomize; for z:=1 to 4 do for sp:=1 to high(Myarray)do myarray[sp,z]:=random(101) end; procedure TForm1.Button1Click(Sender: TObject); begin fuellen; end; procedure TForm1.Button2Click(Sender: TObject); var a1,a2 : string; sp : integer; begin memo1.Visible := true; a1 := ''; for sp:=1 to 4 do a1 := a1+ ' '+inttostr(myarray[1,sp]); memo1.lines.add (a1); a2 := ''; for sp:=1 to 4 do a2 := a2+ ' '+inttostr(myarray[2,sp]); memo1.lines.add (a2); end; procedure TForm1.Button3Click(Sender: TObject); var row,col : integer; begin stringgrid1.Visible:= true; for row:= 0 to 2 do for col:= 0 to 4 do stringgrid1.cells[col,row]:=inttostr(myarray[row+1,col+1]) end; procedure TForm1.Button4Click(Sender: Tobject); var a1,a2 : string; sp : integer; begin edit3.Visible:=true; Edit1.Visible:= true; a1 := ''; for sp:=1 to 4 do a1 := a1+ ' '+inttostr(myarray[1,sp]); edit3.text := a1; a2:= ''; for sp:=1 to 4 do a2 := a2+ ' '+inttostr(myarray[2,sp]); edit1.text := a2; end; procedure TForm1.Button7Click(Sender: TObject); begin close end; procedure TForm1.Button6Click(Sender: TObject); var i,summe:integer; mitte:real; begin edit2.Visible:=true; summe := 0; for i := Low(Myarray) to High(Myarray) do summe := Summe + Myarray[i]; mitte := summe / 4; end; edit2.Text:= inttostr(summe); end. |
Re: Mittelwert von Myarray
Das ist ja auch ein 2-dimensionales Array.
|
Re: Mittelwert von Myarray
Myarray[i] ist das ein Array of Integer.
|
Re: Mittelwert von Myarray
o__O hatte ich vergessen zu erwähnen :oops:
Es handelt sich auch um Delphi 6 |
Re: Mittelwert von Myarray
@Markus:
Zitat:
|
Re: Mittelwert von Myarray
Delphi-Quellcode:
for i := Low(Myarray) to High(Myarray) do
for j := Low( MyArray[i] to High( MyArray[i]) do Summe := Summe + MyArray[i,j]; |
Re: Mittelwert von Myarray
Code:
Jetz gehts schon besser aber irgendwie bekomme ich die Fehlermeldung "[Hinweis] uZufall.pas(133): Auf 'summe' zugewiesener Wert wird niemals benutzt" und "[Hinweis] uZufall.pas(130): Variable 'mitte' wurde deklariert, aber in 'TForm1.Button6Click' nicht verwendet"
procedure TForm1.Button6Click(Sender: TObject);
var i,j,summe:integer; mitte:real; begin edit2.Visible:=true; summe := 0; for i := Low(Myarray) to High(Myarray) do for j := Low( MyArray[i]) to High( MyArray[i]) do Summe := Summe + MyArray[i,j]; end; mitte:= Summe/4; edit2.Text:= inttostr(mitte); end; |
Re: Mittelwert von Myarray
Delphi-Quellcode:
for i := Low(Myarray) to High(Myarray) do
for j := Low( MyArray[i]) to High( MyArray[i]) do begin Summe := Summe + MyArray[i,j]; inc( anzahl); end; mitte:= Summe/ anzahl; edit2.Text:= inttostr(mitte); |
Re: Mittelwert von Myarray
edit: hab das Problem gelöst :D
danke für ale die zeit geopfert haben um mir zu helfen ;) |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:50 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz