Autor Beitrag
mav016
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

Win XP SP2

BeitragVerfasst: So 25.09.05 14:27 
Mann soll ein Programm mit 10 Fragen machen(Fragen wo die Antwort eine Jahreszahl ist)!!
Die Jahreszahlen sind in einer Listbox enthalten(und das habe ich auch geschafft; Zahlen von 1900-2010).
Es werden speedbuttons benötigt um die ANtwort richtig bzw. falsch anzuzeigen!
EIn Button mit Start und Nächste Frage wird benötigt!
Wird eine Frage nicht beantwortet zählt sie als Falsch.
Ein Feld zeigt den Punktestand

Mein Problem ist wie ich die Zahlen aus der Listbox als Antwort benützen kann und wie ich zur nächsten Frage komm!!

Bitte Helft mir


M.f.g
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: So 25.09.05 14:43 
Zu den Antworten:

Guck die mal die Eigenschaft
ausblenden Delphi-Quelltext
1:
Listbox1.itemindex					

an.

hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mav016 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

Win XP SP2

BeitragVerfasst: So 25.09.05 14:47 
Ich weiß!!


Aber ich komm nicht drauf wie es geht!!


Danke

M.f.g
hallo
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 450

WIN XP, SuSE 9.3
D3 Prof, D6 Pers, 2005 Pers
BeitragVerfasst: So 25.09.05 15:14 
Der Itemindex gibt das Element an, welches gerade den Fokus (siehe auch onFocus) hat!
listbox1.items[i] gibt denn String an i. Stelle aus!

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.

_________________
Der beste je Programmierte Trojaner: Windows XP
Wäre es nicht adequat, den Usus heterogener Termini zu minimieren?
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: So 25.09.05 15:24 
wenn dus chon ein paar Einträge hast, dann versuch das mal:
ausblenden Delphi-Quelltext
1:
label1.caption:=listbox1.items[0]					


hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mav016 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

Win XP SP2

BeitragVerfasst: So 25.09.05 16:07 
Ich soll ja 10 Fragen machen und die dazugehörigen Antworten programmieren!!
Mit Var fragen: array[1..10] of string und das selbe mit richtige nur wo schreibe ich das hin??
Zweitens wie komm ich zur nächsten Frage???
Und wie mach ich dasm dass er erkennt ob das richtige ausgesucht wurde von der Listbox??


M.f.g

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
mav016 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

Win XP SP2

BeitragVerfasst: So 25.09.05 16:54 
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:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Label1: TLabel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;   i:integer;
Var fragen:array[1..10] of string;
Var richtig:array[1..10] of string;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);

begin
For i:=1900 to 2010 do listbox1.Items.Add(inttostr(i));

fragen[1]:='Wann war der 1.WK? ';
richtig[1]:='1918';
label1.caption:=fragen[1];



end;

procedure TForm1.Button1Click(Sender: TObject);
begin


fragen[2]:='Die naechste WM?';
richtig[2]:='2006';
label1.Caption:=fragen[2];

fragen[3]:='Die naechste EM?';
richtig[3]:='2008?';
label1.Caption:=fragen[3];

end;

end.




Ich komme nicht weiter!! Könnt ihr mir den nicht helfen, es ist nämlich Hausübung und ich habe alles versucht was ich weiß!!


Wie mach ich das, dass er jedes mal wenn ich auf Button 'Nächste Frage' klicke auch zur nächsten Frage geht??
Und wie geht das jetzt das mit der Listbox(die Jahreszahl als Antwort wählen und mit der richtigen Antwort der Frage kontolliert??

BITTE

Danke im Vorraus


M.f.g

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 25.09.05 17:01 
Ein Ansatz für Dich Array of Fragen..
ausblenden 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:
var
  Form1: TForm1;
  Nr: Integer;
  Frage: Array[1..10] of String;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Frage[1]  := 'Hm...';
  Frage[2]  := 'Wie!';
  Frage[3]  := 'Warum!';
  Frage[4]  := 'Weshalb?';
  Frage[5]  := 'Weswegen?';
  Frage[6]  := 'So Richtig.';
  Frage[7]  := 'Problem dabei.';
  Frage[8]  := 'Gestern.';
  Frage[9]  := 'Heut.';
  Frage[10] := 'Morgen...';
  Inc(Nr);
  if Nr=11 then Nr:=1;
  Caption := Frage[Nr];
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
if Nr = Listbox1.ItemIndex +1 then Label1.Caption:='Richtig' else Label1.Caption:='falsch';
end;
mav016 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

Win XP SP2

BeitragVerfasst: Mo 26.09.05 11:50 
Danke Blackheart666!!!

Aber ich versteh das nicht ganz so.
Warum:
ausblenden Delphi-Quelltext
1:
if Nr = Listbox1.ItemIndex +1 then Label1.Caption:='Richtig' else Label1.Caption:='falsch';					


Und wo hast du die richtigen Antworten stehen??


M.f.g

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
mav016 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

Win XP SP2

BeitragVerfasst: Mo 26.09.05 15:47 
KAnn mir den keiner helfen??

Wie geht das zum Beisppiel wenn die Frage falsch ist dass dann er zur nächsten Frage kommt??


M.f.g
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Mo 26.09.05 16:47 
ausblenden 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:
var Fragenr:integer; //globale Variable
{onFormcreate}
Fragenr:=0;
  Frage[1]  := 'Hm...';
  Frage[2]  := 'Wie!';
  Frage[3]  := 'Warum!';
  Frage[4]  := 'Weshalb?';
  Frage[5]  := 'Weswegen?';
  Frage[6]  := 'So Richtig.';
  Frage[7]  := 'Problem dabei.';
  Frage[8]  := 'Gestern.';
  Frage[9]  := 'Heut.';
  Frage[10] := 'Morgen...';
 
  Richtig[1] := '42';
  Richtig[2] := '42';
  Richtig[3] := '42';
  Richtig[4] := '42';
  Richtig[5] := '42';
  Richtig[6] := '42';
  Richtig[7] := '42';
  Richtig[8] := '42';
  Richtig[9] := '42';
  Richtig[10] := '42';

{onBTN click}

inc(fragenr)
label1.caption := Frage[fragenr];


dann musst du noch ein bisschen mit dem Itemindex rumspielen...

hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
mav016 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

Win XP SP2

BeitragVerfasst: Mo 26.09.05 17:27 
Danke hibbert!

Aber wie mach ich das:
ausblenden Delphi-Quelltext
1:
2:
 Frage[1]:='Wann war der 1.WK?';
 Richtig[1]:='1918';


WIe mach ich das ich jetzt von der Listbox 1918 auswähle und bei Frage[1] das als Richtig erklärt(denn von 1900-2010 sind es ja viele Jahreszahlen);;

Ich danke euch!!


M.f.g

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Di 27.09.05 08:21 
Guten Morgen mav016!

Du solltest in der Schule etwas besser aufpassen. ;-)

Jetzt mal alles der Reihe nach:

Zu erst brauchst du zwei Array um die Fragen und die dazugehörengen Antworten zu definieren:
ausblenden Delphi-Quelltext
1:
2:
Var fragen:array[1..10] of string;
Var richtig:array[1..10] of string;

Dann benötigst du auf jeden Fall noch eine Variable in der Du dir merken kannst welche Frage gerade gestellt wird.

ausblenden Delphi-Quelltext
1:
Var aktuell: Integer					


Bevor du mit dem Quiz beginnst musst du noch einige Dinge vorbereiten/mit Werten vorbelgen. Am besten eignet sich dafür das OnCreate-Event der Form. In diesem OnCreate-Event solltest du die Array´s fragen und antworten mit Inhalt füllen. Außerdem musst du die Variable aktuell auf 1 setzen und die Listbox mit den Jahreszahlen füllen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm1.FormCreate(Sender: TObject);
var
  i : integer;
begin
  // Fragen und die Antworten festlegen
  fragen[1]:='Die naechste WM?';
  richtig[1]:='2006';

  fragen[2]:='Die naechste EM?';
  richtig[2]:='2008?';

  {...}

  // Wir beginnen mit der ersten Frge
  aktuell := 1;

  // Listbox mit den Jahreszahlen füllen
  For i := 1900 to 2010 do 
    listbox1.Items.Add (IntToStr (i));

  UpdateFrage;  // siehe kommende Erklärung 
end;

Wie du siehst habe ich in dem OnCreate-Event auch die Procedure UpdateFrage aufgerufen. Diese Procedure musst du natürlich noch definieren und implementieren. In dieser Procedure würde ich das Label für die Frage setzen und die Auswahl in Listbox wieder entfernen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
Procedure TForm1.UpdateFrage;
Begin
  // Die aktuelle Frage im Label darstellen
  Label1.Caption := fragen[aktuell];
  // Die Markierung in der Listbox entfernen
  Listbox1.ItemIndex := -1;
End;

Als nächstes benötigst Du einen Button um zum einen zu prüfen ob die Antwort richtig oder falsch ist, eine entsprechende Meldung darzustellen und um zur nächsten Frage zu springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm1.Button1Click(Sender: TObject);
begin
  // Prüfen ob der User überhaupt in der Listbox etwas angeklickt hat
  If ListBox1.ItemIndex = -1 Then
    MessageDlg ('Du musst in der Listbox eine Antwort markieren', mtInformation, [mbOK], 0)
  Else
    Begin
      // Prüfen ob die Antwort richtig ist
      If Listbox1.Items [Listbox1.ItemIndex] = richtig [aktuell] Then
        Begin
          MessageDlg ('Super, Deine Antwort ist richtig! :-)', mtInformation, [mbOK], 0)

          // Nächste Frage
          aktuell := aktuell + 1;
          UpdateFrage;
        End
      Else
        MessageDlg ('Deine Antwort ist leider falsch. Versuche es noch mal.', mtInformation, [mbOK], 0)
    End;
end;

Was du noch in die Prüfung einbauen solltest ist ob die letzte Frage gestellt wurde. ;-)

So, ich hoffe das hat dir jetzt etwas geholfen. Normalerweise mach ich ja nicht die Hausaufgaben für andere!!

Lg Martin
mav016 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 30

Win XP SP2

BeitragVerfasst: Di 27.09.05 14:21 
Danke Martin!!

Ich habe es schon alleine geschafft.

M.f.g