Discussion Locked

vb for loop

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

hi guys and gals,

i am trying to write some code for a uni project (yes another newbie question). I have written a for loop and when it runs it always returns a value higher than that it was intended to.

I need the loop to iterate 3 times can you please help as this is due tomorrow and i am lost with it.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim counter As Integer
Dim Num1 As Integer
Dim RandomNumber As Integer
Dim RandomClass As New Random()

RandomNumber = RandomClass.Next(1, 20)
Num1 = CInt(TextBox1.Text())
guessone.Items.Add(TextBox1.Text)
Do Until counter = 4
If counter < 4 Then
TextBox1.Clear()
TextBox1.Focus()
ElseIf counter > 3 Then
Me.Button1.Visible = False
Me.Button2.Visible = True
Me.Label5.Visible = True
End If
If Num1 = RandomNumber Then
Me.Label4.Visible = True
Me.Button1.Visible = False
Me.Button2.Visible = True
Exit Do
End If
Loop
Debug.Print(counter)
End Sub

regards tim

6 replies

by tony hopkinson

What's making counter change in value?

What is this code meant to do?

As far as I can see it will just lock up unless Num1 = RandomNumber.

by tony hopkinson

he's trying to do guess three times and you are out.
Maybe...

It's well wrong if that was the objective, that's not a loop but a state machine.

This discussion is closed to new replies.