Lagte nå en liten og lett i VB6, oppgave1 kan hentes på
Rapidshare
Kode
Dim rand As Integer
Dim teller As Integer
Private Sub Command1_Click()
If Command1.Caption = "New Game" Then
teller = 0
rand = Int((100 - 1) * Rnd + 1)
Command1.Caption = "Guess"
Label1.Caption = "Try to find the number between 1 and 100..!"
Text1.Text = " "
Else
teller = teller + 1
If CInt(Text1.Text) > rand Then
Label1.Caption = "Your guess is too high"
End If
If CInt(Text1.Text) < rand Then
Label1.Caption = "Your guess is too low"
End If
If CInt(Text1.Text) = rand Then
Label1.Caption = "Congratulations, your guess was correct. You used " & teller & " guesses..!"
Command1.Caption = "New Game"
End If
End If
End Sub
Private Sub Form_Load()
Label1.Caption = "Try to find the number between 1 and 100..!"
Text1.Text = " "
Command1.Caption = "Guess"
rand = Int((100 - 1) * Rnd + 1)
Form1.Caption = "Random Guess..!"
End Sub
Oppgave2 kan hentes på
Rapidshare
Kode
Dim guess As Integer
Dim teller As Integer
Dim x As Integer
Dim y As Integer
Private Sub Command1_Click()
x = guess
guess = Int((x - y) * Rnd + y)
Label1.Caption = "My guess is " & guess & "..!"
teller = teller + 1
End Sub
Private Sub Command2_Click()
If Command2.Caption = "New Game" Then
Command1.Enabled = True
Command3.Enabled = True
Command2.Caption = "Correct"
teller = 1
x = 100
y = 1
guess = Int((x - y) * Rnd + y)
Label1.Caption = "My guess is " & guess & "..!"
Else
Label1.Caption = "Yay, only " & teller & " guesses..!"
Command1.Enabled = False
Command3.Enabled = False
Command2.Caption = "New Game"
End If
End Sub
Private Sub Command3_Click()
y = guess
guess = Int((x - y) * Rnd + y)
Label1.Caption = "My guess is " & guess & "..!"
teller = teller + 1
End Sub
Private Sub Form_Load()
Command1.Caption = "Too High"
Command2.Caption = "Correct"
Command3.Caption = "Too Low"
teller = 1
x = 100
y = 1
guess = Int((x - y) * Rnd + y)
Label1.Caption = "My guess is " & guess & "..!"
End Sub
EDIT: Endret litt i random koden på oppgave1 da den var random men fulgte et fast mønster,samt tellet verdi i oppgave2 da den viste 1 forlite..
Sist endret av Lanjelin; 15. mars 2008 kl. 23:00.