0

well ive been trying to make an app in VB 2008 Express Edition so that every time my timer ticks it randomly adds a number like it either adds 1 or nothing but having trouble with it since it just does it one time this is my coding for the timer

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        TextBox1.Text = Int(Rnd() * 1)
        Select Case TextBox1.Text
            Case 0
                TextBox1.Text += 0
            Case 1
                TextBox1.Text += 1
        End Select
    End Sub
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by flasy12
0

The mistake you are making is that you are assigning the "rnd()" value to the TextBox's text every time the timer ticks.

This code will work for you:

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        [B]Dim rndInt as Integer = Int(Rnd() * 1)[/B]
        Select Case rndInt
            Case 0
                TextBox1.Text += 0
            Case 1
                TextBox1.Text += 1
   End Select
End Sub

Thanks

Edited by farooqaaa: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.