b[27] AS Button
z AS Integer 'Zufallszahl
PUBLIC SUB Form_Open()
n AS Integer
'es werden 27 Buttons erzeugt
FOR n = 0 TO 26
b[n] = NEW Button(ME) AS "btn"
b[n].Tag = n
b[n].Caption = Str(n + 1)
b[n].Move( 60 + 60 * (n MOD 9), 20 + 52 * ((n - n MOD 9)/9), 60, 32 )
NEXT
TextBox1.Move( 60, 170, 540, 32 )
TextBox2.Move( 230, 220, 50, 32 )
TextLabel1.Move( 60, 220, 150, 32 )
TextLabel1.Text = "Wie oft geraten?"
Button1.Move( 300, 220, 140, 32 )
Button1.Text = "Neu"
Button2.Move( 460, 220, 140, 32 )
Button2.Text = "Schließen"
ME.Text = "Zahlenraten 1 aus 27"
ME.Border = Window.Resizable
ME.W = 660
ME.H = 280
ME.Border = Window.Fixed
ME.Center
Button1_Click
END
PUBLIC SUB btn_Click()
g AS Integer
r AS Integer
r = LAST.Tag
IF z = r THEN
TextBox1.Text = "Richtig geraten, die Zahl ist " & Str(z + 1)
FOR g = 0 TO 26
b[g].Hide
NEXT
b[z].Show
ENDIF
IF z > r THEN
TextBox1.Text = "Die gesuchte Zahl ist größer"
FOR g = 0 TO r
b[g].Hide
NEXT
ENDIF
IF z < r THEN
TextBox1.Text = "Die gesuchte Zahl ist kleiner"
FOR g = r TO 26
b[g].Hide
NEXT
ENDIF
TextBox2.Text = Str(Val(TextBox2.Text) + 1)
END
PUBLIC SUB Button1_Click()
'Neue Zahl, Tasten (wieder) zeigen
n AS Integer
Randomize()
z = Int(Rnd(0,27))
FOR n = 0 TO 26
b[n].Show
NEXT
Textbox1.Text = "Der PC denkt sich eine Zahl von 1 bis 27. Errate die Zahl!"
Textbox2.Text = "0"
END
PUBLIC SUB Button2_Click()
ME.Close
END