按钮输出无限次

时间:2015-11-20 23:22:07

标签: vb.net generator

好吧,所以几个月前我在这里发了一个问题,除了一个功能外,所有的帮助都让它全部工作了。我想要它,以便当按下按钮时它会粘贴一个名字和姓氏,如果你再次按下该按钮,它会再次执行。但是在那一刻,它只能运作一次。这是我的代码:

Public Class HorizonNameGenerator

Dim UsableChars() As String
Dim MyRandom As New Random
Dim FirstNameList() As String = {"Noah", "Liam", "Mason", "Zack", "James", "Jack", "Derick", "Owen", "Blain", "Borris", "Johnny", "Joe", "Joseph", "Terry", "William", "Rory", "John", "Jason", "Daryl", "Alex", "Josh", "Wu", "Gareth", "Carl", "Martin", "Marty", "Vincent", "Vince", "Vinny", "Bobby", "Bob", "Paris", "Jake", "Gage", "Jacob", "Ethan", "Simon", "Elijah", "Michael", "Daniel", "Thomas", "Tom", "Matthew", "Declan", "Logan", "Lucas", "Benjamain", "Aiden", "David", "Andrew", "Andy", "Sam", "Samuel", "Carter", "Henry", "Nathan", "Ed", "Eddy"}
Dim LastNameList() As String = {"Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor", "Anderson", "Thomas", "Jackson", "White", "Maris", "Martin", "Thompson", "Garcia", "Martinez", "Robinson", "Clark", "Rodriguez", "Lewis", "Lee", "Walker", "Hall", "Allen", "Young", "Hernandez", "King", "Wright", "Lopez", "Hill", "Scott", "Greens", "Adams", "Baker", "Gonzalez", "Nelson", "Carter", "Mitchell", "Perez", "Roberts", "Turner", "Phillips", "Campbell", "Parker", "Evans", "Edwards", "Collins", "Stewert"}
Dim FinalName() As String = {""}
Dim Number As Integer = 0
Dim FirstNameIndex As Integer = MyRandom.Next(0, FirstNameList.Count)
Dim LastNameIndex As Integer = MyRandom.Next(0, LastNameList.Count)
Dim FullName As String = FirstNameList(FirstNameIndex) & " " & LastNameList(LastNameIndex)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    TextBox1.Text = FullName
End Sub

End Class

1 个答案:

答案 0 :(得分:0)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim UsableChars() As String
      Dim MyRandom As New Random
      Dim FirstNameList() As String = {"Noah", "Liam", "Mason", "Zack", "James", "Jack", "Derick", "Owen", "Blain", "Borris", "Johnny", "Joe", "Joseph", "Terry", "William", "Rory", "John", "Jason", "Daryl", "Alex", "Josh", "Wu", "Gareth", "Carl", "Martin", "Marty", "Vincent", "Vince", "Vinny", "Bobby", "Bob", "Paris", "Jake", "Gage", "Jacob", "Ethan", "Simon", "Elijah", "Michael", "Daniel", "Thomas", "Tom", "Matthew", "Declan", "Logan", "Lucas", "Benjamain", "Aiden", "David", "Andrew", "Andy", "Sam", "Samuel", "Carter", "Henry", "Nathan", "Ed", "Eddy"}
      Dim LastNameList() As String = {"Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor", "Anderson", "Thomas", "Jackson", "White", "Maris", "Martin", "Thompson", "Garcia", "Martinez", "Robinson", "Clark", "Rodriguez", "Lewis", "Lee", "Walker", "Hall", "Allen", "Young", "Hernandez", "King", "Wright", "Lopez", "Hill", "Scott", "Greens", "Adams", "Baker", "Gonzalez", "Nelson", "Carter", "Mitchell", "Perez", "Roberts", "Turner", "Phillips", "Campbell", "Parker", "Evans", "Edwards", "Collins", "Stewert"}
      Dim FinalName() As String = {""}
      Dim Number As Integer = 0
      Dim FirstNameIndex As Integer = MyRandom.Next(0, FirstNameList.Count)
      Dim LastNameIndex As Integer = MyRandom.Next(0, LastNameList.Count)
      Dim FullName As String = FirstNameList(FirstNameIndex) & " " & LastNameList(LastNameIndex)
     TextBox1.Text = FullName
End Sub

您需要将代码放入按钮单击中。你拥有它的方式,它只会显示它在脚本开头生成的第一个名称,因为它不会重新填充新值。