VB十二生肖代码怎么做
时间: 2023-10-13 12:22:30 浏览: 164
下面是一个简单的VB代码示例,可以生成随机的十二生肖:
```
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim zodiac() As String = {"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"} '十二生肖数组
Dim rand As New Random() '随机数生成器
Dim index As Integer = rand.Next(0, 12) '生成0到11的随机数
MsgBox("你的生肖是:" & zodiac(index))
End Sub
```
当点击按钮时,该代码会生成一个0到11之间的随机数,然后根据这个随机数从十二生肖数组中获取对应的生肖,并在消息框中显示。
阅读全文