General discussion

Locked

vb for loop

By tim ·
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 conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Hmmm, I don't get it

by Tony Hopkinson In reply to vb for loop

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.

Collapse -

Total noob question

by seanferd In reply to Hmmm, I don't get it

Would this increment from 0 or 1?

Collapse -

In VB and VB.Net

by Tony Hopkinson In reply to Total noob question

from zero.

Strings empty, references null, and numbers zeroed, on declaration.

Collapse -

Thanks for satisfying my curiosity

by seanferd In reply to In VB and VB.Net

That may help the OP as well.

Collapse -

Yeah its not incrementing..

by LarryD4 In reply to Hmmm, I don't get it

No way for it to count up..

Collapse -

I think

by Tony Hopkinson In reply to Yeah its not incrementing ...

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.

Back to Windows Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums