Autor Beitrag
DelphiDelphin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 181



BeitragVerfasst: Mo 21.03.05 13:00 
Hallo wie kann ich machen dass ein Zufälliges Wort von 50 in Label1 erscheint.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 21.03.05 13:09 
Zufälliges deutsches Wort oder einfach eine zufällige Buchstabenkombination?
:arrow: Siehe Random und Chr oder Google


Zuletzt bearbeitet von delfiphan am Mo 21.03.05 13:11, insgesamt 1-mal bearbeitet
Ich Bins
ontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 197

Win XP Prof
D5 Prof
BeitragVerfasst: Mo 21.03.05 13:10 
Wie wärs wenn du die 50 Wörter in eine Liste schreibst, dann mit Random(50)+1 eine Zufallszahl generierst, und dann den entsprechenden Eintrag in das Label reinkopierst?

Edit: Mist, zu langsam :D

_________________
Diese Nachricht wurde mit einer Taschenlampe in das offenliegende Ende eines Glasfaserkabels gemorst!
DelphiDelphin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 181



BeitragVerfasst: Mo 21.03.05 13:19 
Genau so mein ich dass 50 von mir ausgewählte wörter
zb
Katze,
Hund,
Kuh,
Esel,
aber habe keine ahnung wie des Geht :cry:
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 21.03.05 13:34 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Var
 Liste: TStringList;
 ZufaelligesWort: String;
begin
 Liste := TStringList.Create;
 Liste.Add('Hund');
 Liste.Add('Katze');
 Liste.Add('Delphin');
 ZufaelligesWort := Liste.Strings[Random(Liste.Count)];
 Liste.Free;
end;
klezmor
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 558


delphi 6 personal delphi 2005 personal
BeitragVerfasst: Mo 21.03.05 15:03 
Bist du dabei einen Voktrainer zu schreiben? wenn ja könnte ich dir vielleicht helfen?
Diabele$
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 53



BeitragVerfasst: Di 22.03.05 12:25 
So müsste es auch gehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Zufallswort;
begin
  Case random(50)+1 of
    1: Label1.Caption:='Hund';
    2: Label1.Caption:='Kuh';
    3: Label1.Caption:='Katze';
     //  und so weiter...
  end;
end;
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Di 22.03.05 12:34 
Eine weitere Möglichkeit:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Const
  cWoerter : Array [1..4] of String = (
      'Katze', 'Hund', 'Kuh', 'Esel'
    );

procedure TForm1.FormCreate(Sender: TObject);
begin
  Randomize;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Button1.Caption := cWoerter [Random (Length (cWoerter)) +1];
end;

Gruß
Tino
Markus254
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23

Winnt2000
d7 Prof
BeitragVerfasst: Do 28.04.05 20:22 
Es gibt ja Praktisch 1000 möglichkeiten... 8)
Ich würde mir eine Kurze und verstandliche möglichkeit wählen
wie zum Beispiel das von Diabele$
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  procedure TForm1.Zufallswort;  
  begin  
    randomize;
    Case random(50)+1 of  
      1: Label1.Caption:='Hund';  
      2: Label1.Caption:='Kuh';  
      3: Label1.Caption:='Katze';  
       //  und so weiter...  
    end;  
  end;

Es funktionier prima ! 8)
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: Do 28.04.05 20:39 
Oder Du Machst es mit einer Textdatei dann kannst du die ohne Aufwand immer aktualisieren.
Bsp.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm2.SpruchdesTages1Click(Sender: TObject);
var
  Spruch_des_Tages:String;
  Spruch: TStringList;
  Nr: Integer;
begin
 try
   randomize;
   Spruch_des_Tages := 'Sprüche.txt';
   Spruch := TStringList.Create;
   Spruch.LoadFromFile (ExtractFilePath(ParamStr(0)) +(Spruch_des_Tages));
   Nr := random (Spruch.Count);
   RichEdit1.Lines.Add(Spruch.Strings[Nr]);
 except
  ShowMessage('Datei konnte nicht geladen werden !');
 end;
end;
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: Do 28.04.05 20:42 
Hatte ja delfiphan schon Vorgeschlagen hat ich Übersehn.