您好,我从三个数组中随机抽取引号,并将它们拼接到一个标签中。我的代码如下。我如何让它识别并从零数组中拉出。现在,使用代码中的随机数部分,我认为它忽略了每个组中的第一个数组项。谢谢。
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发布于 2014-01-29 00:44:21
基于您对数字生成器不包含零数组的认识,我更改了包含零数组的数字生成器算法
更改您的最后一行
Label1.Text = firstBS_Group(Int(Rnd() * 12)) +“”+ secondBS_Group(Int(Rnd() * 12)) +“”+ thirdBS_Group(Int(Rnd() * 11))
至
firstBS_Group(Int ((11 -0+ 1) * Rnd + 0)) +“”+ secondBS_Group(Int ((11 -0+ 1) * Rnd + 0)) +“”+ thirdBS_Group(Int (10-0+ 1) * Rnd + 0))
发布于 2014-01-29 01:01:36
这看起来是RandBetween()的完美工作。
将代码末尾更改为:
firstBS_Group(worksheetfunction.RandBetween(0,13)) & " " & _
secondBS_Group(worksheetfunction.RandBetween(0,13)) & " " & _
thirdBS_Group(worksheetfunction.RandBetween(0,12))注意代码中"&“符号的使用。这是连接文本的VBA方法。加号是数学符号,有时会咬你一口。
https://stackoverflow.com/questions/21411218
复制相似问题