VB.net 随机数每个到不同的标签 [英] VB.net random numbers each to different label

查看:26
本文介绍了VB.net 随机数每个到不同的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个函数,它返回随机数,而不会在除以,"的同一个标签中重复.如何将所有 6 个值返回到 6 个不同的标签?

<前>公开课测试员公共 ds 作为新数据集公共 strSQL 作为字符串公共 cmd 作为新的 MySqlCommand公共博士作为 MySqlDataReaderDim intNumber 作为整数Dim arrNumber(0 到 5) 作为整数Dim i, x, y 作为整数Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 处理Button1.ClickLabel1.Text = ""对于 x = 0 到 5开始:随机化()intNumber = Int((49 * Rnd()) + 1)对于 y = 0 到 5如果 intNumber = arrNumber(y) 那么转到开始万一下一个arrNumber(x) = intNumber下一个对于 i = 0 到 5Label1.Text = (arrNumber(i))下一个结束子结束类

解决方案

Dim arrNumber(0 To 5) As Integer'从你的标签创建数组:Dim aLabels() As Label = {Label1, Label2, Label3, Label4, Label5, Label6}

在你的循环中

对于 i = 0 到 5aLabels(i).Text = (arrNumber(i))下一个

I have this function which returns random numbers without repeating in same label divided by ",". How can I return all 6 values to 6 different labels?

Public Class Tester
    Public ds As New DataSet
    Public strSQL As String

    Public cmd As New MySqlCommand

    Public dr As MySqlDataReader

    Dim intNumber As Integer
    Dim arrNumber(0 To 5) As Integer
    Dim i, x, y As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Label1.Text = ""



        For x = 0 To 5
    Start:
            Randomize()
            intNumber = Int((49 * Rnd()) + 1)
            For y = 0 To 5

                If intNumber = arrNumber(y) Then
                    GoTo Start
                End If
            Next y


            arrNumber(x) = intNumber

        Next x

        For i = 0 To 5
            Label1.Text = (arrNumber(i))
        Next

    End Sub

End Class

解决方案

Dim arrNumber(0 To 5) As Integer
'Create the array from your labels:
Dim aLabels() As Label = {Label1, Label2, Label3, Label4, Label5, Label6}

in your loop

For i = 0 To 5
    aLabels(i).Text = (arrNumber(i))
Next

这篇关于VB.net 随机数每个到不同的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆