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

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 6 Years Ago by farooqaaa: n/a

This question has already been answered. Start a new discussion instead.