Announcement

Collapse
No announcement yet.

Problem mit If Anweisungen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem mit If Anweisungen

    Hallo an alle,

    ich habe folgendes Problem ich habe ein Editfeld wo mich Beträge eintrage dieses möchte ich mit folgender Abfrage prüfen und dementsprechend die Auswhlen treffen

    procedure TForm1.BitBtn1Click(Sender: TObject);
    var i, t, g, h: Real;

    begin
    i := strtofloat(edit1.text);
    t := 2500;
    g := 15000;
    h := 15001;
    if i > t then Checkbox1.Checked := true;
    Checkbox2.Checked := false;
    Checkbox3.Checked := false;
    if i > t then Checkbox2.Checked := true;
    Checkbox1.Checked := false;
    Checkbox3.Checked := false;
    if i < g and if i > h then Checkbox3.Checked := true;
    Checkbox1.Checked := false;
    Checkbox2.Checked := false;
    if checkbox1.Checked = True then Combobox1.Visible := True;
    Combobox2.Visible := False;
    Combobox3.Visible := False;
    if checkbox2.Checked = True then Combobox2.Visible := True;
    Combobox1.Visible := False;
    Combobox3.Visible := False;
    if checkbox3.Checked = True then Combobox3.Visible := True;
    Combobox2.Visible := False;
    Combobox1.Visible := False;
    end;

    Ich hoffe es kann mir da jemand helfen ich bekomme es nicht hin das er den richtigen Wert ermittel und mir dann die entsprechende Combobox öffnet.

    Bis denne

    Michael

  • #2
    Meinst du das?

    <span style="font-family: Courier New, Times New Roman, Arial; font-size: 8pt;">&nbsp;<span style="font-weight: bold;">procedure</span>&nbsp;TForm1.BitBtn1Click(Sender:&nbsp;TObjec t);&nbsp;
    &nbsp;<span style="font-weight: bold;">var</span>&nbsp;i,&nbsp;t,&nbsp;g,&nbsp;h:&nbsp;Real;&n bsp;
    &nbsp;&nbsp;
    &nbsp;<span style="font-weight: bold;">begin</span>&nbsp;
    &nbsp;i&nbsp;:=&nbsp;strtofloat(edit1.text);&nb sp;
    &nbsp;t&nbsp;:=&nbsp;2500;&nbsp;
    &nbsp;g&nbsp;:=&nbsp;15000;&nbsp;
    &nbsp;h&nbsp;:=&nbsp;15001;&nbsp;
    &nbsp;<span style="font-weight: bold;">if</span>&nbsp;i&nbsp;&gt;&nbsp;t&nbsp;<span style="font-weight: bold;">then</span>&nbsp;Checkbox1.Checked&nbsp;:=&nbsp;true;&nb sp;
    &nbsp;Checkbox2.Checked&nbsp;:=&nbsp;false;&nbs p;
    &nbsp;Checkbox3.Checked&nbsp;:=&nbsp;false;&nbs p;
    &nbsp;<span style="font-weight: bold;">if</span>&nbsp;i&nbsp;&gt;&nbsp;t&nbsp;<span style="font-weight: bold;">then</span>&nbsp;Checkbox2.Checked&nbsp;:=&nbsp;true;&nb sp;
    &nbsp;Checkbox1.Checked&nbsp;:=&nbsp;false;&nbs p;
    &nbsp;Checkbox3.Checked&nbsp;:=&nbsp;false;&nbs p;
    &nbsp;<span style="font-weight: bold;">if</span>&nbsp;i&nbsp;&lt;&nbsp;g&nbsp;<span style="font-weight: bold;">and</span>&nbsp;<span style="font-weight: bold;">if</span>&nbsp;i&nbsp;&gt;&nbsp;h&nbsp;<span style="font-weight: bold;">then</span>&nbsp;Checkbox3.Checked&nbsp;:=&nbsp;true;&nb sp;
    &nbsp;Checkbox1.Checked&nbsp;:=&nbsp;false;&nbs p;
    &nbsp;Checkbox2.Checked&nbsp;:=&nbsp;false;&nbs p;
    &nbsp;<span style="font-weight: bold;">if</span>&nbsp;checkbox1.Checked&nbsp;=&nbsp;True&nbsp ;<span style="font-weight: bold;">then</span>&nbsp;Combobox1.Visible&nbsp;:=&nbsp;True;&nb sp;
    &nbsp;Combobox2.Visible&nbsp;:=&nbsp;False;&nbs p;
    &nbsp;Combobox3.Visible&nbsp;:=&nbsp;False;&nbs p;
    &nbsp;<span style="font-weight: bold;">if</span>&nbsp;checkbox2.Checked&nbsp;=&nbsp;True&nbsp ;<span style="font-weight: bold;">then</span>&nbsp;Combobox2.Visible&nbsp;:=&nbsp;True;&nb sp;
    &nbsp;Combobox1.Visible&nbsp;:=&nbsp;False;&nbs p;
    &nbsp;Combobox3.Visible&nbsp;:=&nbsp;False;&nbs p;
    &nbsp;<span style="font-weight: bold;">if</span>&nbsp;checkbox3.Checked&nbsp;=&nbsp;True&nbsp ;<span style="font-weight: bold;">then</span>&nbsp;Combobox3.Visible&nbsp;:=&nbsp;True;&nb sp;
    &nbsp;Combobox2.Visible&nbsp;:=&nbsp;False;&nbs p;
    &nbsp;Combobox1.Visible&nbsp;:=&nbsp;False;&nbs p;
    &nbsp;<span style="font-weight: bold;">end</span>;&nbsp;&nbsp;</Span>
    &#10
    If it's there and you can see it – it's REAL
    If it's there and you can't see it – it's TRANSPARENT
    If it's not there and you can see it – it's VIRTUAL
    If it's not there and you can't see it – it's GONE!

    Comment


    • #3
      Meinst du das? Ich habs zwar nicht ausprobiert, müsste aber funzen. Mit den wenigen Infos, die du gepostet hast, denke ich, dass du das meinst.

      <span style="font-family: Courier New, Times New Roman, Arial; font-size: 8pt;">&nbsp;<span style="font-weight: bold;">procedure</span>&nbsp;TForm1.BitBtn1Click(Sender:&nbsp;TObjec t);&nbsp;
      &nbsp;<span style="font-weight: bold;">var</span>&nbsp;i,&nbsp;t,&nbsp;g,&nbsp;h:&nbsp;Real;&n bsp;
      &nbsp;<span style="font-weight: bold;">begin</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;:=&nbsp ;StrToFloat(Edit1.Text);&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t&nbsp;:=&nbsp ;2500;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g&nbsp;:=&nbsp ;15000;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h&nbsp;:=&nbsp ;15001;&nbsp;
      &nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold;">if</span>&nbsp;i&nbsp;&gt;&nbsp;t&nbsp;<span style="font-weight: bold;">then</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">begin</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Checkbox1.Checke d&nbsp;:=&nbsp;True;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Checkbox2.Checke d&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Checkbox3.Checke d&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">end</span>;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold;">if</span>&nbsp;(i&nbsp;&lt;&nbsp;g)&nbsp;<span style="font-weight: bold;">and</span>&nbsp;(i&nbsp;&gt;&nbsp;h)&nbsp;<span style="font-weight: bold;">then</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">begin</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Checkbox3.Checke d&nbsp;:=&nbsp;True;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Checkbox1.Checke d&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Checkbox2.Checke d&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">end</span>;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold;">if</span>&nbsp;Checkbox1.Checked&nbsp;=&nbsp;True&nbsp ;<span style="font-weight: bold;">then</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">begin</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox1.Visibl e&nbsp;:=&nbsp;True;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox2.Visibl e&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox3.Visibl e&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">end</span>;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold;">if</span>&nbsp;Checkbox2.Checked&nbsp;=&nbsp;True&nbsp ;<span style="font-weight: bold;">then</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">begin</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox2.Visibl e&nbsp;:=&nbsp;True;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox1.Visibl e&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox3.Visibl e&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">end</span>;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight: bold;">if</span>&nbsp;Checkbox3.Checked&nbsp;=&nbsp;True&nbsp ;<span style="font-weight: bold;">then</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">begin</span>&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox3.Visibl e&nbsp;:=&nbsp;True;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox2.Visibl e&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Combobox1.Visibl e&nbsp;:=&nbsp;False;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;<span style="font-weight: bold;">end</span>;&nbsp;
      &nbsp;<span style="font-weight: bold;">end</span>;&nbsp;</Span>

      Gruß, Christian
      If it's there and you can see it – it's REAL
      If it's there and you can't see it – it's TRANSPARENT
      If it's not there and you can see it – it's VIRTUAL
      If it's not there and you can't see it – it's GONE!

      Comment


      • #4
        Hallo Christian,

        besten Dank für deinen Lösungsansatz, ich habe ihn gestestet aber leider funktioniert er auch nicht, ich bekomme immer nur checkbox1 aktiviert. Ich versuche mein Problem mal näher zu beschreiben:

        Folgende Problemstellung ich möchte ein Programm schreiben welches je nachdem welcher Wert im Edit1 steht eine Checkbox sichtbar machen wo die entsprechenden Werte dann zur weiteren Verarbeitung ausgewählt werden können.

        alswo wenn ich einen Wert zwischen unter 2500 habe soll Checkbox1 aktiviert werden wenn der wert zischen 2501 und 15000 ist soll checkbox2 und wenn der wert größer als 1500 ist soll checkbox3 aktiviert werden.

        Ich hoffe ich konnte meine Problematik besser beschreiben.

        Bis denne Michae

        Comment


        • #5
          Mir ist das Ganze nicht klar. In dem Beispiel findet man am Anfang zB folgendes:
          ...
          if i > t then Checkbox1.Checked := true;
          Checkbox2.Checked := false;
          Checkbox3.Checked := false;
          if i > t then Checkbox2.Checked := true;
          ...
          die gleiche Bedingung gilt für Checkbox1 und Checkbox2 ?
          In diesem Fall würde ich das so schreiben:
          ...
          Checkbox1.Checked := i > t;
          Checkbox2.Checked := Checkbox1.Checked;
          ...
          damit wäre das leichter lesbar.<br>
          Und diese Zeile
          ...
          if i < g and if i > h then Checkbox3.Checked := true;
          ...
          hat mit den angegebenen Daten keinen Sinn, da es keine Zahl gibt, die kleiner als 15000 und trotzdem grösser als 15001 ist, oder? Außerdem würde ich das eher so schreiben:
          if (i < g) and (i > h) then ...<br>
          Das mit der Comboboxanzeige geht auch so (wenn ich die Frage richtig verstanden habe):
          ...
          Combobox1.Visible := Checkbox1.Checked;
          Combobox2.Visible := Checkbox2.Checked;
          Combobox3.Visible := Checkbox3.Checked;
          ...<br>
          bye, Helmu

          Comment


          • #6
            Aha, da haben sich jetzt die Einträge etwas überschnitten, aber damit wird das Problem schon klarer:
            ...
            checkbox1.enabled := i <= 2500;
            checkbox2.enabled := (i > 2500) and (i <= 15000);
            checkbox3.enabled := i > 15000;
            Combobox1.Visible := Checkbox1.Checked;
            Combobox2.Visible := Checkbox2.Checked;
            Combobox3.Visible := Checkbox3.Checked; <br>
            das sollte reichen ... :-)

            Comment

            Working...
            X