vb怎么产生20个不同的字母?
答案:2 悬赏:10
解决时间 2021-11-09 13:30
- 提问者网友:晨熙污妖王
- 2021-11-08 16:23
vb怎么产生20个不同的字母?
最佳答案
- 二级知识专家网友:野性且迷人
- 2021-11-08 17:19
随机产生20个不重复的A~Z之间的字母(包括A 和Z)字符
Dim a(20) As String
Dim b(26, 2) As Integer
For i = 1 To 26
b(i, 1) = 64 + i
b(i, 2) = 0
Next i
Dim n As Integer, m As Integer, s As String
n = 1
s = ""
Do While n <= 20
Randomize
m = Int(Rnd * 26) + 1
If b(m, 2) = 0 Then
a(n) = Chr(b(m, 1))
b(m, 2) = 1
n = n + 1
End If
Loop
Dim max As Integer, min As Integer
max = 65
min = 90
For i = 1 To 20
s = s & a(i) & " "
If Asc(a(i)) > max Then
max = Asc(a(i))
End If
If Asc(a(i)) < min Then
min = Asc(a(i))
End If
Next i
Print s
Print Chr(max)
Print Chr(min)
Dim a(20) As String
Dim b(26, 2) As Integer
For i = 1 To 26
b(i, 1) = 64 + i
b(i, 2) = 0
Next i
Dim n As Integer, m As Integer, s As String
n = 1
s = ""
Do While n <= 20
Randomize
m = Int(Rnd * 26) + 1
If b(m, 2) = 0 Then
a(n) = Chr(b(m, 1))
b(m, 2) = 1
n = n + 1
End If
Loop
Dim max As Integer, min As Integer
max = 65
min = 90
For i = 1 To 20
s = s & a(i) & " "
If Asc(a(i)) > max Then
max = Asc(a(i))
End If
If Asc(a(i)) < min Then
min = Asc(a(i))
End If
Next i
Print s
Print Chr(max)
Print Chr(min)
全部回答
- 1楼网友:何必打扰
- 2021-11-08 17:45
'以下代码产生30个区分大小写的不同字母
private sub command1_click()
dim i as integer, j as integer, ich(30) as integer, ch as string, ach(30) as string
i = 0
randomize
do while i < 30
ch = int(rnd * 52)
for j = 1 to i
if ich(j) = ch then exit for
next
if j > i then
i = i + 1
ich(i) = ch
end if
loop
for i = 1 to 30
if ich(i) < 26 then
ach(i) = chr(65 + ich(i)) '0-25为大写字母
else
ach(i) = chr(97 + ich(i) - 26) '26-51为小写字母
end if
next
for i = 1 to 30
print ach(i) & " ";
if i mod 10 = 0 then print
next
end sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息