Autor Beitrag
BaSs-Ti
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 01.11.05 16:19 
Wir müssen grad in Info eine Suchfunktion erstellen, wo Zahlen in einer Listbox (ListBox1) gesucht werden müssen und als Ergebnis in der Listbox ausgegeben werden muss, dass die Zahl vorhanden ist oder nicht. Wie kann ich das realisieren??
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Di 01.11.05 16:22 
Das Ergebnis der Suche soll in die Listbox ?

Etwas allgemein deine Frage.
Was willst du genau ?
- Wie man sucht ?
- Wie man auf den Inhalt der Listbox zugreift ?
- Wie man das Ergebnis darstellt ?

Bitte etwas genauer.


Zuletzt bearbeitet von azubi_20 am Di 01.11.05 16:25, insgesamt 1-mal bearbeitet
BaSs-Ti Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 01.11.05 16:24 
ja, es soll in diese Listbox

alles, und zwar den quelltext, da ich schon mehrere beispiele (lösungen) ohne erfolg wíeder entfernen musste

Moderiert von user profile iconTino: Beiträge zusammengefasst.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 01.11.05 16:29 
Heißt das, dass in der gleichen Listbox das Ergebnis stehen soll? Also wenn nciht dann:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var i:integer //lokal, nicht global deklarieren!!!

for i := 0 to listbox1.items.count-1 do
begin

  strtoint(if listbox1.items[i])=zahl then
  listbox2.items.add(inttostr(zahl)+' is drin!!!');
  //kommt drauf an, ob du die Zahl als Variable hast oder in ein EditFeld eingibst(dann       heißt es logischerweise anders :wink:
end;


So, da du wie gesagt nich genau definiert hast, wie du die zahl eingibst, wei0 ich nich ob ich dir damit jetzt geholfen hab. Ein paarmehr infos wären nicht schlecht

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
e.coli
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Di 01.11.05 16:30 
user profile iconazubi_20 hat folgendes geschrieben:

Was willst du genau ?
- Wie man sucht ?
- Wie man auf den Inhalt der Listbox zugreift ?
- Wie man das Ergebnis darstellt ?


wir brauchen den quellcode um aus einer listbox in der wir vorher die zahlen eingeben können zu suchen, ob die gesuchte zahl, die wir (in edit1) eingeben, schon eingegeben wurde... wenn ja soll da ne message stehen "zahl gibt es" oder halt bei nein "zahl nicht vorhanden" oder so..
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Di 01.11.05 16:35 
Also, mal sehen ob ich das richtig verstanden habe :
Du hast eine Listbox mit Zahlen drin (guck dir mal die Egenschaft "items" an)
Du gibst irgendwo eine Zahl ein.
Du machst ne Schleife über die Items in der Listbox und prüfst darin, ob deine eingegebene Zahl da auftaucht. (Stichwort "items.count")
Du löscht alle Items (?) und gibst "Gefunden" oder "nicht gefunden" in die Listbox ein ("items[0]").

So in etwa ?
BaSs-Ti Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Di 01.11.05 16:37 
alle items nicht löschen, sonst aber richtig
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Di 01.11.05 16:40 
Der Knackpunkt ist hier listbox1.items
Diese sind wie ein Array aufgebaut.
count = Anzahl Elemente
items[0] = 1. Element
items[1] = 2. Element
items[2] = 3. Element
usw.
add = hinzufügen
clear = löschen

Schau dir mal die Hilfe dazu an.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 01.11.05 18:05 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var i:integer //lokal, nicht global deklarieren!!!
for i := 0 to listbox1.items.count-1 do
begin

  if listbox1.items[i])=edit1.text then
  listbox2.items.add(edit1.text);

end;


Also so dürfte es richtig sein glaub ich :gruebel:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 02.11.05 12:40 
Was spricht dagegen IndexOf zu benutzen?
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 02.11.05 15:11 
@ Luckie:

Also ich weiß jetz wirklich nich, was du mit indexof meinst :gruebel: Würde denn meine Variante nicht gehen? :nixweiss:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mi 02.11.05 15:14 
user profile iconKoller hat folgendes geschrieben:
@ Luckie:

Also ich weiß jetz wirklich nich, was du mit indexof meinst :gruebel: Würde denn meine Variante nicht gehen? :nixweiss:


Dann schau doch mal in die Online-Heilfe zu IndexOf ( Eigenschaft von TStrings ).

_________________
Bravery calls my name in the sound of the wind in the night...
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Mi 02.11.05 15:16 
Hallo :wink2:

user profile iconKoller hat folgendes geschrieben:
Also ich weiß jetz wirklich nich, was du mit indexof meinst :gruebel:

IndexOf ist eine Funktion die eine StringList durchsucht und die Position (wenn gefunden) zurück gibt.

user profile iconKoller hat folgendes geschrieben:
Würde denn meine Variante nicht gehen? :nixweiss:

Doch, bis auf einen Syntaxfehler schon. Allerdings ist IndexOf wohl einfacher zu implementieren. ;-)

Lg Martin

_________________
Ein Nutzer der Ecke ;-)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 02.11.05 15:49 
@ Martin 1966

Wo liegt denn der Syntaxfehler?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Mi 02.11.05 15:55 
ausblenden Delphi-Quelltext
1:
 if listbox1.items[i])=edit1.text then					

_________________
Ein Nutzer der Ecke ;-)