您好我从三个数组中随机引用并在标签中将它们拼接在一起。我的代码如下。如何让它识别并从零数组中拉出来。现在用我的随机数部分代码我相信它会忽略每个组中的第一个数组项。谢谢。
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
答案 0 :(得分:0)
基于您假设数字生成器不包含零数组,我已经更改了包含零数组的数字生成器算法
更改最后一行
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))
答案 1 :(得分:0)
这看起来像是RandBetween()的完美工作。
将代码的结尾更改为:
firstBS_Group(worksheetfunction.RandBetween(0,13)) & " " & _
secondBS_Group(worksheetfunction.RandBetween(0,13)) & " " & _
thirdBS_Group(worksheetfunction.RandBetween(0,12))
注意使用“&”代码中的符号。哪种是连接文本的VBA方式。加号是用于数学的,有时可能会咬你。