Dim p As String
Dim i As Integer
Dim num As Integer, num2 As Integer
Dim op As Integer, ris As Integer
Dim temp As Integer, errore As Integer
Dim t As Integer, tempo As Single
Private Sub cmdgo_Click()
cmdrec.Visible = False
Timer1.Enabled = True
i = i + 1
lblop.Visible = True
txtris.Visible = True
cmdok.Visible = True
cmdgo.Visible = False
Randomize
num = Int(Rnd * 9)
op = Int(Rnd * 3) + 1
num2 = Int(Rnd * 10)
Select Case op
Case 1
lblop.Caption = num & " + " & num2 & " = "
ris = num + num2
Case 2
If num < num2 Then
temp = num
num = num2
num2 = temp
End If
lblop.Caption = num & " - " & num2 & " = "
ris = num - num2
Case 3
lblop.Caption = num & " x " & num2 & " = "
ris = num * num2
' Case 4
'lblop.Caption = num & " : " & num2 & " = "
End Select
End Sub
Private Sub cmdok_Click()
If Int(txtris.Text) <> ris Then
errore = errore + 1
lblerr.Caption = "Errori : " & errore
End If
If i >= 10 Then
tempo = t / 100
tempo = tempo + errore
MsgBox "Hai totalizzato " & errore & " errori" _
& vbCrLf & "Tempo totalizzato : " & tempo & " secondi", vbInformation, "Game over"
cmdrec.Visible = True
Timer1.Enabled = False
t = 0
Call Form_Load
Exit Sub
End If
cmdok.Visible = False
lblop.Caption = ""
txtris.Text = ""
txtris.Visible = False
Call cmdgo_Click
End Sub
Private Sub cmdrec_Click()
Dim nome As String, tot As Single
nome = InputBox("Inserisci il tuo nome", "Nome record")
If nome = "" Then nome = "Sconosciuto"
Open p For Append As 1
Print #1, nome & " : " & tempo
Close #1
cmdrec.Visible = False
End Sub
Private Sub Form_Load()
i = 0
cmdgo.Visible = True
lblop.Caption = ""
txtris.Text = ""
txtris.Visible = False
cmdok.Visible = False
p = App.path & "\" & "record.dat"
lblerr.Caption = "Errori : 0"
errore = 0
End Sub
Private Sub Timer1_Timer()
t = t + 1
End Sub
Private Sub txtris_Change()
If Not IsNumeric(txtris.Text) Then
txtris.Text = ""
cmdok.Enabled = False
Else
cmdok.Enabled = True
End If
End Sub
Private Sub txtris_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Call cmdok_Click
End If
End Sub