VB随机生成字符串

大神来也_715 |浏览328次
收藏|2022/04/12 07:04

满意回答

2022/04/12 07:22

以下简单的程序可实现(每次按command1生成一组)Private Sub Command1_Click()Randomize '初始化随机函数发生器,没有它,每次生成随机数相同 For i = 1 To 16 x = Int(Rnd() * 3) If x = 0 Then a = a + Chr(Int(Rnd * 10) + 48) '数字 ASCII为48到58 Else If x = 1 Then a = a + Chr(Int(Rnd * 26) + 65) '大写 Else a = a + Chr(Int(Rnd * 26) + 97) '小写 End If End If NextPrint a End Sub测试结果

whoami1978

其他回答(1)
  • RandomizeFor i = 1 To 16 '字符串的数量Select Case Rnd * Rnd * 35Case Is < 1b = "a"a = a & bCase Is < 2b = "b"a = a & bCase Is < 3b = "c"a = a & bCase Is < 4b = "d"a = a & bCase Is < 5b = "e"a = a & bCase Is < 6b = "f"a = a & bCase Is < 7b = "g"a = a & bCase Is < 8b = "h"a = a & bCase Is < 9b = "i"a = a & bCase Is < 10b = "j"a = a & bCase Is < 11b = "k"a = a & bCase Is < 12b = "l"a = a & bCase Is < 13b = "m"Case Is < 14b = "n"a = a & bCase Is < 15b = "o"a = a & bCase Is < 16b = "p"a = a & bCase Is < 17b = "q"a = a & bCase Is < 18b = "r"a = a & bCase Is < 19b = "s"a = a & bCase Is < 20b = "t"a = a & bCase Is < 21b = "u"a = a & bCase Is < 22b = "v"a = a & bCase Is < 23b = "w"a = a & bCase Is < 24b = "x"a = a & bCase Is < 25b = "y"a = a & bCase Is < 26b = "z"a = a & bCase Elseb = "。"a = a & bEnd SelectNext i'vb6写过来的,自己写的,虽然笨……vb6粘贴过来还没空行,又要一个一个空行……'以上代码可以生成小写的26字母和句号,随机的,放在变量a中。亲测可用。'如果需要其他的,那就在单分支语句里加,我写不下去了。'望采纳!
    回答于 2022/04/12 07:52
0人关注该问题
+1

 加载中...