Autor Beitrag
thefight3r
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Sa 31.05.08 13:39 
Hallo,
brauche dringend Hilfe bei meinem Delphi-Programm.
Es soll die Buchstabenhäufigkeit eines Textes bestimmen, sie in Prozente angeben
(Gesamtzahl /Anzahl eines Buchstabens*100%) und in einen stringgrid schreiben.

Dann soll das Programm die Prozente (Rel.[relative] Häufigkeit) mit der Buchstabenhäufigkeit von deutschen, englischen und französischen Texten überprüfen.
(mit Hilfe der Tabelle: http://de.wikipedia.org/wiki/Buchstabenhäufigkeit ).

Delphi ließt den Text ein und analysiert ihn auch, d.h. "zählt" die Buchstaben und gibt sie im stringgrid aus.

Allerdings tritt ein EconvertError auf, "" sein kein gültiger Integerwert, wenn die procedure Prozente aufgerufen wird.



(procedure analysiere funtioniert)


Mein Programm(der problematische Teil):

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
var
Form1: TForm1;
S:String;
implementation

{$R *.dfm}

procedure TForm1.FormActivate(Sender: TObject);
var zaehler:Integer;
begin
 memo1.Clear;
 Stringgrid1.Cells[1,0]:= 'Abs.Haüfigkeit';
 Stringgrid1.Cells[2,0]:= 'Rel.Haüfigkeit';
 For zaehler :=1 to 26 do
  Begin
   Stringgrid1.Cells[0,Zaehler]:=Chr(zaehler+96);
   Stringgrid1.Cells[1,Zaehler]:='0';
   Stringgrid1.Cells[2,Zaehler]:='0';
  end;
end;

procedure analysiere(S:string); // funktioniert
var zaehler: integer ;
begin
for zaehler:=1 to Length(S) do
Begin
IF (Ord(S[zaehler])>96) AND (Ord(S[zaehler])<123) THEN
Form1.StringGrid1.Cells[1,ORD(S[zaehler])-96]:=IntToStr(StrToInt(Form1.StringGrid1.Cells[1,ORD(S[zaehler])-96])+1);
end;
end;



procedure Prozente; // funktioniert nicht
var x,z:integer;

begin
z:=0;
begin
for x:=1 to 26 do
begin
z:=z+StrToInt(Form1.stringgrid1.cells[1,x]);
end;
Form1.stringgrid1.cells[2,z]:=IntToStr(Round(StrToInt(Form1.StringGrid1.cells[1,x]) div z * 10000) div 100);
Form1.Label1.caption:=IntToStr(z);
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var z:integer;
begin
S:=Memo1.Text;
analysiere(S);
Prozente;
end;´

PS: Im Anhang ist mein Programm
vielen dank für eine schnelle Hilfe

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Einloggen, um Attachments anzusehen!
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 31.05.08 15:40 
und wo tritt der fehler auf?
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Sa 31.05.08 16:01 
user profile iconthefight3r hat folgendes geschrieben:

Es soll die Buchstabenhäufigkeit eines Textes bestimmen, sie in Prozente angeben
(Gesamtzahl /Anzahl eines Buchstabens*100%) und in einen stringgrid schreiben.


Ist es nicht (Anzahl eines Buchstaben/Anzahl aller Buchstaben)*100% ?
Muck
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 98
Erhaltene Danke: 8

Win 8, Win 7, Vista, Win XP
Delphi XE3, Delphi 2009, Delphi 2007, Delphi 5
BeitragVerfasst: Sa 31.05.08 16:21 
Hallo,

Dein Problem ist wohl ein leere Zelle in dem Grid

Statt StrToInt( x )
benutze

StrToIntDef( x ,0)

und Dein Problem sollte geloest werden. Ein leerer String wird dann wie Null interpretiert.

Ausserdem ist wohl ein Fehler in Prozente Cells[2,z] ist wohl falsch.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
 
procedure Prozente;
var x,z:integer;  
begin  
z:=0;  
for x:=1 to 26 do begin  
  z:=z+StrToIntDef(Form1.stringgrid1.cells[1,x],0);  
end;  
for x:=1 to 26 do begin  
  Form1.stringgrid1.cells[2,x]:=IntToStr(Round(StrToIntDef(Form1.StringGrid1.cells[1,x],0) * 10000 div z) div 100);  
end;  
Form1.Label1.caption:=IntToStr(z);  
end;


Sollte so laufen...

Bye

Markus
thefight3r Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Sa 31.05.08 17:50 
danke an markus, hat mir sehr geholfen, es geht endlich...
thefight3r Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Sa 31.05.08 18:32 
kann mir jemand bitte noch sagen, wie man auf 2 stellen runden kann
und ein "Prozentzeichen" hinter den ausgegebenen Wert setzen kann???

Form1.stringgrid1.cells[2,x]:=IntToStr(Round(StrToIntDef(Form1.StringGrid1.cells[1,x],0) * 10000 div z) div 100);

danke
nagel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 708

Win7, Ubuntu 10.10

BeitragVerfasst: Sa 31.05.08 19:13 
Ungefähr: Form1.Stringgrid1.Cells[2, x] := FloatToStr(Round(StrToIntDef(Form1.StringGrid1.Cells[1, x], 0) * 10000 / z) / 100) + ' %';
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 31.05.08 22:20 
Alternativ auch mit RoundTo

AXMD
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 01.06.08 00:08 
Hallo,

oder
ausblenden Delphi-Quelltext
1:
s := Format('%f%%',[123.4567]);					

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
thefight3r Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: So 01.06.08 10:00 
Titel: DANKE!!!
sehr vielen dank an alle, die mir geholfen haben, das problem ist perfekt gelöst, DANKE !