![]() |
Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Hey Leute,
ich hab noch eine Frage... Ich möchte gerne das mein "Taschenrechner" die Editfelder mit dem dazugehörigen Hacken in der Checkbox addiert. Mein Problem ist es das immer nur zwei zahlen zusammengerechnet werden oder halt nicht nur die wo ein hacken in der Checkbox ist :( .... Hier der Code:
Code:
Vielen Dank schon mal für die Hilfe :-D
unit Unit1;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; CheckBox4: TCheckBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label7: TLabel; Label8: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; RadioButton1: TRadioButton; RadioButton2: TRadioButton; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button2Click(Sender: TObject); begin if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox2.Checked =true then begin label7.Caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit2.Text)); end; if radiobutton1.Checked = true and checkbox1.Checked =true and checkbox3.Checked =true then begin label7.caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit3.Text)); end; if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox4.Checked =true then begin label7.Caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit4.Text)); end; if radiobutton1.Checked = true and checkbox2.Checked =true and checkbox3.Checked =true then begin label7.caption:= floattostr(strtofloat(edit2.Text)+strtofloat(edit3.Text)); end; if radiobutton1.Checked = true and Checkbox2.Checked = true and Checkbox4.Checked =true then begin label7.Caption:= floattostr(strtofloat(edit2.Text)+strtofloat(edit4.Text)); end; if radiobutton1.Checked = true and checkbox3.Checked =true and checkbox4.Checked =true then begin label7.caption:= floattostr(strtofloat(edit3.Text)+strtofloat(edit4.Text)); end; if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox2.Checked =true and Checkbox3.Checked =true then begin label7.Caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit2.Text)+strtofloat(edit3.Text)); end; if radiobutton1.Checked = true and checkbox1.Checked =true and checkbox3.Checked =true and Checkbox4.Checked =true then begin label7.caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit3.Text)+strtofloat(edit4.Text)); end; if radiobutton1.Checked = true and Checkbox4.Checked = true and Checkbox2.Checked =true and Checkbox3.Checked =true then begin label7.Caption:= floattostr(strtofloat(edit4.Text)+strtofloat(edit2.Text)+strtofloat(edit3.Text)); end; if radiobutton1.Checked = true and checkbox1.Checked =true and checkbox2.Checked =true and Checkbox3.Checked =true and Checkbox4.Checked =true then begin label7.caption:= floattostr(strtofloat(edit1.Text)+strtofloat(edit2.Text)+strtofloat(edit3.Text)+strtofloat(edit4.Text)); end; end; procedure TForm1.Button1Click(Sender: TObject); begin close; end; end. Grüße ItsMe1 |
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Delphi-Quellcode:
if radiobutton1.Checked = true and Checkbox1.Checked = true and Checkbox2.Checked =true then
Ohh das mag DeddyH gar nicht ;) gruss |
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Ahhh.... bin neu hier (hab erst angefangen mit Programmieren) kannst du mir bitte sagen was da falsch ist und wie ich es verbessern kann
Danke |
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Code:
procedure TForm1.Button2Click(Sender: TObject);
begin if radiobutton1.Checked then begin label7.Caption := '0'; if checkbox1.Checked then label7.caption := floattostr(strtofloat(label7.caption) + strtofloat(edit1.Text)); if checkbox2.Checked then label7.caption := floattostr(strtofloat(label7.caption) + strtofloat(edit2.Text)); if checkbox3.Checked then label7.caption := floattostr(strtofloat(label7.caption) + strtofloat(edit3.Text)); if checkbox4.Checked then label7.caption := floattostr(strtofloat(label7.caption) + strtofloat(edit4.Text)); end; end; |
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Zitat:
[edit] ![]() |
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Danke für die schnelle Antwort
Gruss |
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Nachtrag: wenn Du mehrere Vergleiche als Bedingung verknüpfen willst, musst Du jeden einzelnen Vergleich in Klammern einschließen.
Delphi-Quellcode:
if (a = 10) and (b < 5) and (c = 42) then
|
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
[OT]
Wie kommt man eigentlich darauf bei einer CheckBox vom einem Hacken zu sprechen? Das scheint immer beliebter zu werden, aber ... Wird hier auf etwas herumgehackt? Ist hier ein Hacker am Werk? Wurde etwas mit einem Hackbrett erfasst? Haken oder Häkchen könnte ich verstehen, aber so... :gruebel: [/OT] |
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Zitat:
|
AW: Nur das größte Ergebnis wird angegeben (Rechner mit Checkbox und Radiobox)
Delphi-Quellcode:
wobei der Zugriff über eigene Listen oder Array mit den Komponenten flotter wäre.
var
i:Integer; sum:Double; begin sum := 0; if RadioButton1.checked then begin for I := 1 to 4 do if TCheckBox(FindComponent('Checkbox' + IntToStr(i))).Checked then Sum := Sum + StrToFloat(TEdit(FindComponent('Edit' + IntToStr(i))).Text); Label7.Caption := FloatToStr(sum); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:09 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