vb 生成26字母 给出调用了多少次随机数

来源:百度知道 编辑:UC知道 时间:2024/06/27 08:53:48
生成26个互不相同的字母(aA算一个)按生成的顺序输出,并给出调用了多少次随机数。

'添加窗体Form1,按钮Command1,然后添加如下代码:
Private Sub Command1_Click()
    Dim i%, n%, temp$, s$
    Cls
    Do Until (Len(s) = 26)
        Randomize
        temp = Int(Rnd() * 26) + 97
        If InStr(s, Chr(temp)) = 0 Then
            Print Chr(temp)
            s = s & Chr(temp)
        End If
        n = n + 1
    Loop
    Print "一共调用了"