Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VBA中提取随机引号_Vba - Fatal编程技术网

在VBA中提取随机引号

在VBA中提取随机引号,vba,Vba,嗨,我正在从三个数组中随机抽取引号,并将它们拼成一个标签。我的代码如下。如何让它识别并从零数组中提取。现在,对于代码中的随机数部分,我认为它忽略了每组的第一个数组项。多谢各位 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Declare the first array and how many items i

嗨,我正在从三个数组中随机抽取引号,并将它们拼成一个标签。我的代码如下。如何让它识别并从零数组中提取。现在,对于代码中的随机数部分,我认为它忽略了每组的第一个数组项。多谢各位

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'Declare the first array and how many items it will hold
        Dim firstBS_Group(13) As String
        firstBS_Group(0) = "24/7"
        firstBS_Group(1) = "multi-Tier"
        firstBS_Group(2) = "30,000 foot"
        firstBS_Group(3) = "B-B"
        firstBS_Group(4) = "smart"
        firstBS_Group(5) = "six-sigma"
        firstBS_Group(6) = "critical-path"
        firstBS_Group(7) = "dynamic"
        firstBS_Group(8) = "leveraged"
        firstBS_Group(9) = "aligned"
        firstBS_Group(10) = "targeted"
        firstBS_Group(11) = "shared"
        firstBS_Group(12) = "cooperative"


        'Declare the second array and how many items it will hold
        Dim secondBS_Group(13) As String
        secondBS_Group(0) = "empowered"
        secondBS_Group(1) = "sticky"
        secondBS_Group(2) = "value-added"
        secondBS_Group(3) = "oriented"
        secondBS_Group(4) = "centric"
        secondBS_Group(5) = "distributed"
        secondBS_Group(6) = "clustered"
        secondBS_Group(7) = "branded"
        secondBS_Group(8) = "outside-the-box"
        secondBS_Group(9) = "positioned"
        secondBS_Group(10) = "networked"
        secondBS_Group(11) = "focused"
        secondBS_Group(12) = "accelerated"

        'Declare the third array and how many items it will hold
        Dim thirdBS_Group(12) As String
        thirdBS_Group(0) = "process"
        thirdBS_Group(1) = "tipping-point"
        thirdBS_Group(2) = "solution"
        thirdBS_Group(3) = "architecture"
        thirdBS_Group(4) = "core-competency"
        thirdBS_Group(5) = "strategy"
        thirdBS_Group(6) = "mindshare"
        thirdBS_Group(7) = "portal"
        thirdBS_Group(8) = "space"
        thirdBS_Group(9) = "vision"
        thirdBS_Group(10) = "paradigm"
        thirdBS_Group(11) = "mission"

        Label1.Text = firstBS_Group(Int(Rnd() * 12)) + " " + secondBS_Group(Int(Rnd() * 12)) + " " + thirdBS_Group(Int(Rnd() * 11))

    End Sub
End Class

根据你的估计,数字生成器不包含零数组,我已经更改了包含零数组的数字生成器算法

改变你的最后一行

Label1.Text=firstBS_组(Int(Rnd()*12))+“”+ 第二组(Int(Rnd()*12))+“”+thirdBS_组(Int(Rnd()*11))

第一个BS_群(Int((11-0+1)*Rnd+0))+“”+第二个BS_群(Int) ((11-0+1)*Rnd+0))+“”+thirdBS_群(Int((10-0+1)* Rnd+0)


这似乎是RandBetween()的完美工作

将代码结尾更改为:

firstBS_Group(worksheetfunction.RandBetween(0,13)) & " " & _
secondBS_Group(worksheetfunction.RandBetween(0,13)) & " " & _ 
thirdBS_Group(worksheetfunction.RandBetween(0,12))
注意代码中使用的“&”符号。这是VBA连接文本的方式。加号代表数学,有时会咬你