在VB中,随机生成小写字母的代码要怎么写
答案:2 悬赏:50
解决时间 2021-03-13 01:51
- 提问者网友:陪我到最后
- 2021-03-12 08:28
在VB中,随机生成小写字母的代码要怎么写
最佳答案
- 二级知识专家网友:我们只是兮以城空
- 2021-03-12 08:59
Private Sub Command1_Click()
Randomize
Print Chr(Int(Rnd * 26 + 97))
End Sub
Randomize
Print Chr(Int(Rnd * 26 + 97))
End Sub
全部回答
- 1楼网友:duile
- 2021-03-12 09:32
a-z的ascii码为97-122
所以随机产生97-122的数字然后chr就得到字母了
至于平移比如:a的ascii码为97 c的ascii码为99,所以只需要+2就平移两个字母了··
最后的y和z则需要判断,z的ascii码为122,+2之后为124,超出小写字母范围,于是通过计算使他等于98得到b。。。。。。
option explicit const le as integer = 10 private sub command1_click() dim i as integer text1.text = "随机" randomize for i = 1 to le text1.text = text1.text & chr(int(26 * rnd + 97)) next timer1.interval = 800 ' msgbox len(text1.text) end sub
private sub timer1_timer() dim i as integer, n as integer text2.text = "平移" for i = 3 to le + 2 n = asc(mid(text1.text, i, 1)) + 2 if n > 122 then n = n - 122 + 96 end if text2.text = text2.text & chr(n) next end sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯