2014-01-28 35 views
0

嗨我拉從三個數組中的隨機引號,並將它們拼湊在一起的標籤。我的代碼如下。我如何讓它識別並從零數組中拉出。現在用我的隨機數部分代碼,我相信它會忽略每個組的第一個數組項。謝謝。在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 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

根據您asuumption該號碼生成器不包括零陣,我已經改變了數生成算法,其中包括零陣列

影響您的最終線

Label1.Text = firstBS_Group(中間體(RND()* 12))+ 「」 + secondBS_Group(中間體(RND()* 12))+ 「」 + thirdBS_Group(中間體(RND()* 11))

爲了

firstBS_Group(INT((11 - 0 + 1)*了Rnd + 0))+ 「」 + secondBS_Group(中間體 ((11 - 0 + 1)*了Rnd + 0))+「 「+ thirdBS_Group(INT((10 - 0 + 1)* 賽第一輪+ 0))

0

這看起來像是一個完美的工作爲RANDBETWEEN()。

更改代碼的末尾:

firstBS_Group(worksheetfunction.RandBetween(0,13)) & " " & _ 
secondBS_Group(worksheetfunction.RandBetween(0,13)) & " " & _ 
thirdBS_Group(worksheetfunction.RandBetween(0,12)) 

注意在代碼中使用了「&」符號。這是VBA連接文本的方式。加號是數學,有時會咬你。