zufallsauswahl für wörter

tengelchen

Grünschnabel
hallo,

ich habe folgendes problem :

ich möchte ein programm schreiben, indem ich mir zufällig von mir vorgegebene wörter ausgeben lassen kann und suche jetzt nach einem befehl dafür. sowas wie random nur halt für string gibt es sowas ? :confused:

wär schön wenn ihr mir helfen könntet,

danke, tengelchen.
 
hat sich erledigt danke :)

aber jez hab ich n anderes problem ....

das ist mein quelltext :


procedure freizeit (f:string);
var zufall :integer;
begin


if f='Fruehling' then
randomize;
zufall:=random(11)+1;
if zufall=1 then form1.label1.caption := 'Spaziergang';
if zufall=2 then form1.Label1.Caption := 'Billard';
if zufall=3 then form1.Label1.Caption := 'Schwimmbad';
if zufall=4 then form1.Label1.Caption := 'Kuchen backen';
if zufall=5 then form1.Label1.Caption := 'Solarium';
if zufall=6 then form1.Label1.Caption := 'Bowling';
if zufall=7 then form1.Label1.Caption := 'Shoppen';
if zufall=8 then form1.Label1.Caption := 'Kino';
if zufall=9 then form1.Label1.Caption := 'Skaten';
if zufall=10 then form1.Label1.Caption := 'Sport';
if zufall=11 then form1.Label1.Caption := 'Eis essen';



if f='Sommer' then
randomize;
zufall:=random(13)+1;
if zufall=1 then form1.label1.caption := 'Im See schwimmen';
if zufall=2 then form1.Label1.Caption := 'Billard';
if zufall=3 then form1.Label1.Caption := 'Picknick';
if zufall=4 then form1.Label1.Caption := 'Kuchen backen';
if zufall=5 then form1.Label1.Caption := 'Solarium';
if zufall=6 then form1.Label1.Caption := 'Bowling';
if zufall=7 then form1.Label1.Caption := 'Shoppen';
if zufall=8 then form1.Label1.Caption := 'Kino';
if zufall=9 then form1.Label1.Caption := 'Skaten';
if zufall=10 then form1.Label1.Caption := 'Sport';
if zufall=11 then form1.Label1.Caption := 'Eis essen';
if zufall=12 then form1.Label1.Caption := 'Erdbeeren pluecken';
if zufall=13 then form1.Label1.Caption := 'Heissluftballonfahrt';



if f='Herbst' then
randomize;
zufall:=random(9)+1;
if zufall=1 then form1.label1.caption := 'Schwimmbad';
if zufall=2 then form1.Label1.Caption := 'Kino';
if zufall=3 then form1.Label1.Caption := 'Billard';
if zufall=4 then form1.Label1.Caption := 'Kuchen backen';
if zufall=5 then form1.Label1.Caption := 'Solarium';
if zufall=6 then form1.Label1.Caption := 'Bowling';
if zufall=7 then form1.Label1.Caption := 'Shoppen';
if zufall=8 then form1.Label1.Caption := 'Strasse kehren';
if zufall=9 then form1.Label1.Caption := 'Skaten';



if f='Winter' then
randomize;
zufall:=random(12)+1;
if zufall=1 then form1.label1.caption:= 'Schneemann bauen';
if zufall=2 then form1.label1.caption:= 'Billard';
if zufall=3 then form1.label1.caption:= 'Kino';
if zufall=4 then form1.label1.caption:= 'Kuchen backen';
if zufall=5 then form1.label1.caption:= 'Solarium';
if zufall=6 then form1.label1.caption:= 'Bowling';
if zufall=7 then form1.label1.caption:= 'Shoppen';
if zufall=8 then form1.label1.caption:= 'im Bett einbuddeln';
if zufall=9 then form1.label1.caption:= 'romantischen Abend';
if zufall=10 then form1.label1.caption:= 'rodeln';
if zufall=11 then form1.label1.caption:= 'Schlittschuh fahren';
if zufall=12 then form1.label1.caption:= 'Schwimmbad';


end;


procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
var activity:string;
begin
activity:=combobox1.Text;
freizeit(activity);
end;

procedure TForm1.Button2Click(Sender: TObject);
var zufall :integer;
f:string;
begin


f:=combobox1.Text;
if f='Fruehling' then
randomize;
zufall:=random(11)+1;
if zufall=1 then form1.label1.caption := 'Spaziergang';
if zufall=2 then form1.Label1.Caption := 'Billard';
if zufall=3 then form1.Label1.Caption := 'Schwimmbad';
if zufall=4 then form1.Label1.Caption := 'Kuchen backen';
if zufall=5 then form1.Label1.Caption := 'Solarium';
if zufall=6 then form1.Label1.Caption := 'Bowling';
if zufall=7 then form1.Label1.Caption := 'Shoppen';
if zufall=8 then form1.Label1.Caption := 'Kino';
if zufall=9 then form1.Label1.Caption := 'Skaten';
if zufall=10 then form1.Label1.Caption := 'Sport';
if zufall=11 then form1.Label1.Caption := 'Eis essen';



if f='Sommer' then
randomize;
zufall:=random(13)+1;
if zufall=1 then form1.label1.caption := 'Im See schwimmen';
if zufall=2 then form1.Label1.Caption := 'Billard';
if zufall=3 then form1.Label1.Caption := 'Picknick';
if zufall=4 then form1.Label1.Caption := 'Kuchen backen';
if zufall=5 then form1.Label1.Caption := 'Solarium';
if zufall=6 then form1.Label1.Caption := 'Bowling';
if zufall=7 then form1.Label1.Caption := 'Shoppen';
if zufall=8 then form1.Label1.Caption := 'Kino';
if zufall=9 then form1.Label1.Caption := 'Skaten';
if zufall=10 then form1.Label1.Caption := 'Sport';
if zufall=11 then form1.Label1.Caption := 'Eis essen';
if zufall=12 then form1.Label1.Caption := 'Erdbeeren pluecken';
if zufall=13 then form1.Label1.Caption := 'Heissluftballonfahrt';



if f='Herbst' then
randomize;
zufall:=random(9)+1;
if zufall=1 then form1.label1.caption := 'Schwimmbad';
if zufall=2 then form1.Label1.Caption := 'Kino';
if zufall=3 then form1.Label1.Caption := 'Billard';
if zufall=4 then form1.Label1.Caption := 'Kuchen backen';
if zufall=5 then form1.Label1.Caption := 'Solarium';
if zufall=6 then form1.Label1.Caption := 'Bowling';
if zufall=7 then form1.Label1.Caption := 'Shoppen';
if zufall=8 then form1.Label1.Caption := 'Strasse kehren';
if zufall=9 then form1.Label1.Caption := 'Skaten';



if f='Winter' then
randomize;
zufall:=random(12)+1;
if zufall=1 then form1.label1.caption:= 'Schneemann bauen';
if zufall=2 then form1.label1.caption:= 'Billard';
if zufall=3 then form1.label1.caption:= 'Kino';
if zufall=4 then form1.label1.caption:= 'Kuchen backen';
if zufall=5 then form1.label1.caption:= 'Solarium';
if zufall=6 then form1.label1.caption:= 'Bowling';
if zufall=7 then form1.label1.caption:= 'Shoppen';
if zufall=8 then form1.label1.caption:= 'im Bett einbuddeln';
if zufall=9 then form1.label1.caption:= 'romantischen Abend';
if zufall=10 then form1.label1.caption:= 'rodeln';
if zufall=11 then form1.label1.caption:= 'Schlittschuh fahren';
if zufall=12 then form1.label1.caption:= 'Schwimmbad';

end;
end.

wenn ich jez das programm starte zeigt mir mein programm nur die aktivitäten für den Winter :( aber ich seh meinen Fehler nicht
 
das is total unübersichtlich xD..naja ich würde vorschlagen, überall nach diesen zuweisungen

if f='Fruehling' then

ein begin zu setzen, und danach wenn das letzte if vorbei ist, wieder ein end...das hat damit zu tun, dass nach dem if nur immer eine anweisung befolgt wird, mehr nicht.
das ganze würde ich noch mit einer case anwendung machen, anstatt mit den ganzen If's...

Anstatt der ganzen Strings, mach eventuell eine Integer Variable, die du dann je nach Jahreszeit zuweist, so hätte ich es jedenfalls gemacht.

du brauchst nur einmal randomize schreiben ..und zwar am anfang vom programm, da du hier keine anderen unterprogramme hast..was ich aber fast empfehlen würde.

was ich noch nicht verstehe...wieso hast du extra ein unterprogramm, und dann doch unter dem button nochmal das gleiche?
 
danke dir werd des mal probiern :)


also des isn programm, dass mir zeigt was ich zu ner bestimmten jahreszeit so machn kann in miner freizeit und da hab ich mir gedacht, wenn mir das was mir das programm anzeigt nich gefällt dann kann ich ja nen butten "weiter" machen und es zeigt mir das nächste .. darum hab ich das alles nochmal unter den button geschrieben ... wär sicher auch einfacher gegangen, aber ich bin anfänger wie man sicher merkt ;)
 
achso ;)..dann geb ich dir wirklich den Tipp, für jede Jahreszeit ein Unterprogramm zu machen, und dann überall aufzurufen, so sparst du Tipp, oder in dem Fall wohl Kopierarbeit ;)
 
naja nun is ja erstma zuspät .. ach und nochma danke, gut :)
jez hab ich nur noch ein einziges problem ...
wenn ich eine aktivität weitergedrückt hab dann kann die jeder zeit wieder kommen ... kann man doch sicher auch ausstellen oder
 
du könntest die zahl im hauptprogramm zwischenspeichern, und mit einer if abfrage prüfen, ob es die selbe zahl wie vorher ist. wenn ja, einfach nochmal random.
 
Zurück