Autor Beitrag
arminho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Mo 07.03.05 14:56 
hallo leute, habe ein Problem mit einem Vergleich zweier Zahlen...
unswar sollen bestimmte Bilder bei bestimmten Situationen geladen werden.
wenn der inhalt von label 12 größer ist (die zahl) als der von label 11 dann soll lev5.bmp geladen werden, wenn 12 kleiner ist als 11 soll lev1.bmp geladen werden und wenn label 11 und 12 gleich sind soll lev3.bmp geladen werden...
soweit so gut. ich glaube ich habe es auch richtig formuliert im code (unten könnt ihr es mal prüfen)
Nun ist das Problem aber: Es funktioniert alles, nur wenn 12 kleiner ist als 11 zeigt er mir trotzdem lev3.bmp an...nur bei einem unterschied von 100 zeigt er es richtig an, wenn der unterschied größer ist, zeigt er eben lev3 an...
kann einer helfen bitte?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm8.Label8Click(Sender: TObject);
begin
label11.caption:=IntToStr(StrToInt(edit5.text) + StrToInt(edit6.text) + StrToInt(edit7.text) + StrToInt(edit8.text));
label12.caption:=IntToStr(StrToInt(edit1.text) + StrToInt(edit2.text) + StrToInt(edit3.text) + StrToInt(edit4.text));
image1.visible:=true;
if label12.caption>label11.caption then image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev5.bmp');
if label12.caption=label11.caption then image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev3.bmp');
if label12.caption<label11.caption then image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev1.bmp');
end;
wdbee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 628
Erhaltene Danke: 1



BeitragVerfasst: Mo 07.03.05 14:59 
Die Eigenschaft Caption ist ein String und keine Zahl. StrToInt(Caption) ist wohl dass, was du meinst.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 07.03.05 15:00 
Vor dem Vergleichen solltest du den Text in eine Zahl umwandeln (StrToInt).

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm8.Label8Click(Sender: TObject);
begin
  label11.caption:=IntToStr(StrToInt(edit5.text) + StrToInt(edit6.text) + StrToInt(edit7.text) + StrToInt(edit8.text));
  label12.caption:=IntToStr(StrToInt(edit1.text) + StrToInt(edit2.text) + StrToInt(edit3.text) + StrToInt(edit4.text));
image1.visible:=true;

if StrToInt (label12.caption) > StrToInt (label11.caption) then
  image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev5.bmp')
else if StrToInt (label12.caption) = StrToInt (label11.caption) then
  image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev3.bmp')
else
  image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev1.bmp');
end;


Zuletzt bearbeitet von Tino am Mo 07.03.05 15:01, insgesamt 1-mal bearbeitet
arminho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Mo 07.03.05 15:00 
moment jetzt...wo genau? :?
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Mo 07.03.05 15:01 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm8.Label8Click(Sender: TObject);
begin
label11.caption:=IntToStr(StrToInt(edit5.text) + StrToInt(edit6.text) + StrToInt(edit7.text) + StrToInt(edit8.text));
label12.caption:=IntToStr(StrToInt(edit1.text) + StrToInt(edit2.text) + StrToInt(edit3.text) + StrToInt(edit4.text));
image1.visible:=true;
if StrToInt(label12.caption)>StrToInt(label11.caption) then image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev5.bmp');
if StrToInt(label12.caption)=StrToInt(label11.caption) then image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev3.bmp');
if StrToInt(label12.caption)<StrToInt(label11.caption) then image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev1.bmp');
end;

Sieht dann so ^^ aus.. ;)


Zuletzt bearbeitet von WeBsPaCe am Mo 07.03.05 15:02, insgesamt 1-mal bearbeitet
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 07.03.05 15:02 
user profile iconarminho hat folgendes geschrieben:
moment jetzt...wo genau? :?

S. meinen Beitrag.
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Mo 07.03.05 15:03 
user profile iconTino hat folgendes geschrieben:
S. meinen Beitrag.

Oder meinen... :rofl:
arminho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Mo 07.03.05 15:03 
ok habs jetzt gesehn..danke für eure hilfe
arminho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Mo 07.03.05 15:07 
noch ne frage wo ich grad dabei bin...
unswar wird jetzt einfach geprüft ob das eine größer ist als das andere...kann ich ihm aber auch sagen, dass wenn es um 50% größer ist als das andere dann soll er lev3 laden wenn es aber 80% größer ist dann lev5 etc.
also bei einer bestimmten Varianz der Zahlen verschiedene bilder laden.

oder wenn es nicht mit Prozent geht dann wenigstens z.B. wenn es um 1000 größer ist...oder um 500 kleiner
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Mo 07.03.05 15:12 
Da musst du einfach noch n bisschen Mathe mit reinstopfen... ;)

z.B. macht
ausblenden Delphi-Quelltext
1:
if StrToInt(Label1.Caption) > StrToInt(Label2.Caption)*(80/100then (..)					

dann das was dahinter steht, wenn Label1 größer ist als 80% von Label2.

Und so weiter... ;)
arminho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Mo 07.03.05 15:14 
ah ok, wusste ich nicht dass man das so leicht dahinter schreiben kann...interessant 8)
zemy
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 207

Win XP Prof.
D7
BeitragVerfasst: Mo 07.03.05 17:54 
Ist dann vieleicht vorteilhafter, wenn du das vorher in Variablen zwirbelst...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm8.Label8Click(Sender: TObject);
Var
L1,L2:integer
begin
  label11.caption:=IntToStr(StrToInt(edit5.text) + StrToInt(edit6.text) + StrToInt(edit7.text) + StrToInt(edit8.text));
  label12.caption:=IntToStr(StrToInt(edit1.text) + StrToInt(edit2.text) + StrToInt(edit3.text) + StrToInt(edit4.text));
image1.visible:=true;

L1:=StrToInt (label11.caption);
L2:=StrToInt (label12.caption);

if L2 > L1 then
  image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev5.bmp')
else if L1 = L2 then
  image1.Picture.loadfromfile(ExtractFilePath(Application.ExeName)+'bilder\lev3.bmp')
else if L1 < L2*0.875+3 then
  // ....
end;


Braucht weniger Rechenzeit, als wenn du immer von Str zu integer umrechnest und es ist besser lesbar...

_________________
LifeIsToShortToThinkAboutTheShortness