I can’t figure out the code for vb.net that would randomize the interval of a certain timer. For each a = a + 1, there would be a different开发者_高级运维 interval, and for each a = 1, a = 2, a = 3 etc. there would be a different text that will be shown on a label.
If you know how to make it possible, please help. Thank you.
i might not quite understand something like this
Dim arrLbls(3) As Label
'an array with 4 elements of type label' 'populating the array'
arrLbls(0) = Label1
arrLbls(1) = Label2
arrLbls(2) = Label3
arrLbls(3) = Label4
'loops trought array'
For i As Int16 = 0 To arrLbls.Length - 1
arrLbls(i).Text = "Label from the array " & i + 1
Next
`
Make use of the Random class
Public Function RandomNumber(ByVal MaxNumber As Integer, _
Optional ByVal MinNumber As Integer = 0) As Integer
'initialize random number generator
Dim r As New Random(System.DateTime.Now.Millisecond)
'if passed incorrect arguments, swap them
'can also throw exception or return 0
If MinNumber > MaxNumber Then
Dim t As Integer = MinNumber
MinNumber = MaxNumber
MaxNumber = t
End If
Return r.Next(MinNumber, MaxNumber)
End Function
精彩评论