Autor Beitrag
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Sa 06.10.07 16:29 
Hey Leute,

ich bekam grad ne Frage wie man prüfen kann, ob eine Zahl in einem Edit-Feld in einem gewissen Wertebereich (1001 - 1005) liegt.
Ich wollte natürlich sofort mit meinem schier endlosen Wissen angeben (hatte sowas ja schließlich früher schon mal gemacht) und musste feststellen, dass mein Wissen scheinbar doch endlich ist :(
Ich hab ihm geschrieben, er solle mal
ausblenden Delphi-Quelltext
1:
if zahl in [1001..1005then ...					

probieren.
Das funktioniert so allerdings nicht.
Ich würde ja die Suche bemühen, aber die hat mir alles geliefert außer das was ich suche *g*

Wie ging das noch gleich?
Bitte helft mir dabei mein Wissen wieder endlos werden zu lassen ;)



Grüße
Daniel
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 480

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 06.10.07 16:35 
ausblenden Delphi-Quelltext
1:
if (zahl >= 1001and (zahl <= 1005then					


Oder suchst du was komplizierteres? :gruebel:

_________________
We are, we were and will not be.
Danny87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Sa 06.10.07 16:38 
OH MEIN GOTT!! :shock: :lol: :oops: :autsch:
Peinlich, peinlich....hab ich mal wieder zu verwirrend gedacht^^
Danke xD
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Sa 06.10.07 16:47 
user profile iconGausi hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
if (zahl >= 1001and (zahl <= 1005then					


Oder suchst du was komplizierteres? :gruebel:


Vielleicht so,
ausblenden Delphi-Quelltext
1:
  if (Zahl-1000in [1,2,3,4,5then					
, :D

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
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: Sa 06.10.07 17:13 
Hallo,

dann so:
ausblenden Delphi-Quelltext
1:
2:
if (Zahl-1000in [1..5then 
  //...

oder so:
ausblenden Delphi-Quelltext
1:
2:
3:
case Zahl of
  1000..1005 : ShowMessage('im Wertebereich');
  end;


:D

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Sa 06.10.07 17:15 
Hey,

ich danke vielmals dafür das es hier besprochen wurde !

EDIT :


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:
procedure TForm1.Button1Click(Sender: TObject);
begin
if (zahl >= 1001and (zahl <= 1005then 
begin
if edit1.text = '1001' then
begin
panel1.Caption := 'Monitor Fujitsu-Siemens' ;
panel2.Caption := '199,99€' ;
end;
if edit1.Text = '1002' then
begin
panel1.caption := 'Festplatte 250 GB' ;
panel2.caption := '89,50€' ;
end;
if edit1.Text = '1003' then
begin
panel1.caption := 'Motherboard mit CPU' ;
panel2.caption := '155,00€' ;
end;
if edit1.Text = '1004' then
begin
panel1.caption := 'DVD-Combolaufwerk' ;
panel2.Caption := '36,90€' ;
end;
if edit1.Text = '1005' then
begin
panel1.caption := 'PC Tower-Gehäuse' ;
panel2.caption := '44,80€' ;
end;
end;


end.


so wirklich funktionieren tut es noch nicht, wie soll ich die Meldung einbauen wenn die Zahl nicht vorhanden ist ?

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 06.10.07 18:05 
Ausgehend davon, dass Zahl ein Integer ist und den gleichen Wert hat, wie edit1.text:
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:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if (zahl >= 1001and (zahl <= 1005then 
  begin
    case zahl of
      1001 : begin
        panel1.Caption := 'Monitor Fujitsu-Siemens' ;
        panel2.Caption := '199,99€' ;
      end;
      1002 : begin
        panel1.caption := 'Festplatte 250 GB' ;
        panel2.caption := '89,50€' ;
      end;
      1003 : begin
        panel1.caption := 'Motherboard mit CPU' ;
        panel2.caption := '155,00€' ;
      end;
      1004 : begin
        panel1.caption := 'DVD-Combolaufwerk' ;
        panel2.Caption := '36,90€' ;
      end;
      1005 : begin
        panel1.caption := 'PC Tower-Gehäuse' ;
        panel2.caption := '44,80€' ;
      end
      else
        ShowMessage('Eigentlich ein unmöglicher Fall');
    end;
  end
  else
  begin
    ShowMessage('Falsche Eingabe');
  end;
end.
An Deinen Einrückungen solltest Du arbeiten. :wink:
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Sa 06.10.07 23:39 
Okay,

danke für dem Source werde mich morgen mal melden !

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
Danny87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: So 07.10.07 04:20 
user profile iconGericasS hat folgendes geschrieben:
Okay,

danke für dem Source werde mich morgen mal melden !


Huch^^
da is ja der Fragesteller xD
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 09.10.07 08:07 
Hey,

ich hab da doch noch eine Frage, hab das ganze jetzt mal weiter geführt, nur wie geb ich ihm zu verstehen das case ** of für das Edit Feld bestimmt ist bzw. vom edit Feld ausgeht, da "zahl" edit1.text sein soll !

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:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if (zahl >= 1001and (zahl <= 1005then
  begin
    case zahl of
      1001 : begin
        panel1.Caption := 'Monitor Fujitsu-Siemens' ;
        panel2.Caption := '199,99€' ;
      end;
      1002 : begin
        panel1.caption := 'Festplatte 250 GB' ;
        panel2.caption := '89,50€' ;
      end;
      1003 : begin
        panel1.caption := 'Motherboard mit CPU' ;
        panel2.caption := '155,00€' ;
      end;
      1004 : begin
        panel1.caption := 'DVD-Combolaufwerk' ;
        panel2.Caption := '36,90€' ;
      end;
      1005 : begin
        panel1.caption := 'PC Tower-Gehäuse' ;
        panel2.caption := '44,80€' ;
      end
      else
        ShowMessage('Eigentlich ein unmöglicher Fall');
    end;
  end
  else
  begin
    ShowMessage('Falsche Eingabe');
  end;
end;
end.

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
TProgger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148

XP
D6, D2007 prof
BeitragVerfasst: Di 09.10.07 08:14 
ganz am Anfang:
Zahl := StrToIntDef(Edit1.Text); ?
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 09.10.07 08:20 
user profile iconTProgger hat folgendes geschrieben:
ganz am Anfang:
Zahl := StrToIntDef(Edit1.Text); ?


oh peinlich :oops:

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 09.10.07 08:40 
Eine weitere Frage stellt sich dann noch für mich , wofür sind diese Zeilen ?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
 end;
      1005 : begin
        panel1.caption := 'PC Tower-Gehäuse' ;
        panel2.caption := '44,80€' ;
      end
      else
       ShowMessage('Eigentlich ein unmöglicher Fall');
    end;
  end
  else
  begin


wenn das hier unten nocheinmal erscheint !

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
 else
  begin
    ShowMessage('Falsche Eingabe');
  end;
end;


Grüße

GericasS

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
TProgger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148

XP
D6, D2007 prof
BeitragVerfasst: Di 09.10.07 08:43 
Edit: Die erste (im case) ShowMessage ist überflüssig, würd ich sagen...
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 09.10.07 08:47 
user profile iconTProgger hat folgendes geschrieben:
Edit: Die erste (im case) ShowMessage ist überflüssig, würd ich sagen...


das dachte ich mir nämlich auch, bewirken tun sie im Endeffekt doch beide das gleiche oder ?

Grüße

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
TProgger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148

XP
D6, D2007 prof
BeitragVerfasst: Di 09.10.07 08:55 
die im case würde ja nie aufgerufen, die zweite erscheint, wenn die Zahl nicht im Bereich ist.
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 09.10.07 09:01 
user profile iconTProgger hat folgendes geschrieben:
die im case würde ja nie aufgerufen, die zweite erscheint, wenn die Zahl nicht im Bereich ist.


ja stimmt, dann mach ich die mal raus !

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 09.10.07 09:07 
Ich habe mich schon gefragt, wann Dir das auffällt. :mrgreen:
Deswegen hatte ich ja schon geschrieben, dass das ein unmöglicher Fall ist.

Du kannst auch einfach diesen Teil rausschmeissen:
ausblenden Delphi-Quelltext
1:
  if (zahl >= 1001and (zahl <= 1005then					

inklusive dem passenden else. Das hat den Vorteil, dass Du bei einem veränderten Zahlen-Bereich nur das Case anpassen musst. Dafür muss natürlich das else für das case erhalten bleiben.
GericasS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 540

Windows Vista Home Premium
D2010, VisualStudio2008
BeitragVerfasst: Di 09.10.07 09:10 
user profile iconjasocul hat folgendes geschrieben:
Ich habe mich schon gefragt, wann Dir das auffällt. :mrgreen:
Deswegen hatte ich ja schon geschrieben, dass das ein unmöglicher Fall ist.


Hey,

danke das du es noch auflöst :lol: aber ich hatte erst heute morgen so wirlich Zeit mir den Source mal anzuschauen.

Zitat:
inklusive dem passenden else. Das hat den Vorteil, dass Du bei einem veränderten Zahlen-Bereich nur das Case anpassen musst. Dafür muss natürlich das else für das case erhalten bleiben.


Danke :D

Grüße

_________________
Alexander N.
Neue Bewaffnung Amilo xi2428 T9300
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: Di 09.10.07 09:13 
Hallo,

und damit es übersichtlich wird noch die Panelbeschriftung in eine Prozedur auslagern:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.SetPanelCaption(sArtikel,sPreis: String);  
begin
  Panel1.Caption := sArtikel;  
  Panel2.Caption := sPreis;
end;

procedure TForm1.Button1Click(Sender: TObject);  
begin
    case zahl of  
      1001 : SetPanelCaption('Monitor Fujitsu-Siemens','199,99€');
      1002 : SetPanelCaption('Festplatte 250 GB','89,50€');
      //...  
      else ShowMessage('Falsche Eingabe');  
    end;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )