Dim animals() As String = {"Dog", "Cat", "Goat", "Cow"}
Dim randomAnimal As Single = Int((UBound(Animals)+1)*Rnd())
以上代码为我提供了一个数组的索引值,而不是字符串。
尝试以下方法,但不起作用:
Dim intIndex As Integer= Int(randomAnimal)
Dim animals() As String = {"Dog", "Cat", "Goat", "Cow"}
Dim randomAnimal As Single = Int((UBound(Animals)+1)*Rnd())
预期结果:需要从数组中获取randomanimal
中的所有动物名。
答案 0 :(得分:0)
您可以尝试以下方法:
dim animals_array, animals_string, animal_random
randomize timer
animals_string = "Dog,Cat,Goat,Cow"
animals_array = split(animals_string, ",")
animal_random = animals_array(int((ubound(animals_array) + 1) * Rnd))