调用随机函数,使要随机出现的字符与随机函数相关,随机数种子与系统时间关联,就行了。
创建一个工程,在Form1上创建一个Text1和一个Command1:
Dim S(4) As String
Private Sub Command1_Click()
Dim n As Integer
Randomize
n = Int(5 * Rnd)
Text1.Text = S(n)
End Sub
Private Sub Form_Load()
S(0) = "Hello!"
S(1) = "亲爱的"
S(2) = "你好!"
S(3) = "对不起!"
S(4) = "再见!"
End Sub
加一句Randomize 语句