vb for loop - TechRepublic
General discussion
March 15, 2009 at 04:25 AM
tim

vb for loop

by tim . Updated 17 years, 4 months ago

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

This discussion is locked

All Comments