如何使用 Randomize 函数来随机化计时器间隔?

发布于 2024-10-28 17:00:57 字数 129 浏览 0 评论 0原文

我无法找出 vb.net 的代码来随机化某个计时器的间隔。对于每个 a = a + 1,都会有不同的间隔,对于每个 a = 1、a = 2、a = 3 等,标签上会显示不同的文本。

如果您知道如何实现这一点,请提供帮助。 谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身仙ぐ女味 2024-11-04 17:00:58

我可能不太明白这样的事情

调暗 arrLbls(3) 作为标签
'具有 4 个标签类型元素的数组'
'填充数组'

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

`

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

`

z祗昰~ 2024-11-04 17:00:58

使用 Random 类

   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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文