VB随机产生10个不重复的大写英文字母,看看我哪边错了
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/10 14:57:04
VB随机产生10个不重复的大写英文字母,看看我哪边错了
Private Sub Command1_Click()
Dim a(1 To 10)
Dim flag As Boolean, i%, j%
Randomize
For i = 1 To 10
Do
a(i) = Int(26 * Rnd) + 65
flag = False
For j = 1 To i - 1
If a(i) = a(j) Then
flag = True
Exit For
End If
Next j
Loop While flg = True
Next i
Print "随机产生10个不重复的大写英文字母:"
For i = 1 To 10
Print Chr(a(i)),
Next i
End Sub
Private Sub Command1_Click()
Dim a(1 To 10)
Dim flag As Boolean, i%, j%
Randomize
For i = 1 To 10
Do
a(i) = Int(26 * Rnd) + 65
flag = False
For j = 1 To i - 1
If a(i) = a(j) Then
flag = True
Exit For
End If
Next j
Loop While flg = True
Next i
Print "随机产生10个不重复的大写英文字母:"
For i = 1 To 10
Print Chr(a(i)),
Next i
End Sub
'试一下:
Private Sub Command1_Click()
Dim a(1 To 10) As String
Dim i As Integer,j As Integer
For i = 1 To 10
Randomize
a(i) = Chr(Int(26 * Rnd) + 65)
If i > 1 Then
For j = 1 To i - 1
If a(i) = a(j) Then Exit For
Next
End If
If j < i And i > 1 Then i = i - 1
Next
MsgBox Join(a,",")
End Sub
再问: 你这样的确可以,我想问为什么我那个错了。而且我的显示方法和你的不一
再答: '给你修改一下,最好的方法是用字典,这个效率太低,如果上万很容易假死机 Private Sub Command1_Click() Dim a(1 To 10) Dim flag As Boolean, i%, j% Randomize For i = 1 To 10 flag = False Do Until flag a(i) = Int(26 * Rnd) + 65 If i = 1 Then Exit Do For j = 1 To i - 1 If a(i) = a(j) Then Exit For Next If j = i Then flag = True Loop Next Print "随机产生10个不重复的大写英文字母:" For i = 1 To 10 Print Chr(a(i)); Next Print End Sub '--------------------------------- '给你用字典写,这方法最好: Private Sub Command1_Click() Dim s As String, n As Long With CreateObject("scripting.dictionary") Do Until n = 10 Randomize s = Chr(Int(26 * Rnd) + 65) If Not .Exists(s) Then .Add s, "" n = n + 1 End If DoEvents Loop MsgBox Join(.keys, ",") End With End Sub
Private Sub Command1_Click()
Dim a(1 To 10) As String
Dim i As Integer,j As Integer
For i = 1 To 10
Randomize
a(i) = Chr(Int(26 * Rnd) + 65)
If i > 1 Then
For j = 1 To i - 1
If a(i) = a(j) Then Exit For
Next
End If
If j < i And i > 1 Then i = i - 1
Next
MsgBox Join(a,",")
End Sub
再问: 你这样的确可以,我想问为什么我那个错了。而且我的显示方法和你的不一
再答: '给你修改一下,最好的方法是用字典,这个效率太低,如果上万很容易假死机 Private Sub Command1_Click() Dim a(1 To 10) Dim flag As Boolean, i%, j% Randomize For i = 1 To 10 flag = False Do Until flag a(i) = Int(26 * Rnd) + 65 If i = 1 Then Exit Do For j = 1 To i - 1 If a(i) = a(j) Then Exit For Next If j = i Then flag = True Loop Next Print "随机产生10个不重复的大写英文字母:" For i = 1 To 10 Print Chr(a(i)); Next Print End Sub '--------------------------------- '给你用字典写,这方法最好: Private Sub Command1_Click() Dim s As String, n As Long With CreateObject("scripting.dictionary") Do Until n = 10 Randomize s = Chr(Int(26 * Rnd) + 65) If Not .Exists(s) Then .Add s, "" n = n + 1 End If DoEvents Loop MsgBox Join(.keys, ",") End With End Sub
VB随机产生10个不重复的大写英文字母,看看我哪边错了
VB随机产生一个英文字母
Vb随机生成长度为[20个大写英文字母、数字]的组合,每五个加一个连字符如何写
求大神帮看VB代码哪边出错了——随机生成10个20到90之间的整数,将其中的素数输出.
vb问题利用随机函数产生80个10~99之间的随机整数,
VB:随机产生 10 个整数,求其中最小的数.若随机产生n个整数又如何实现
如何用excel产生1~68,68个不重复的随机的整数?
随机产生一个四位数的VB编码 谢谢了
用VB编一个程序,随机产生10个100以内的不同的偶数
vb中如何随机产生20个10以内的正整数
vb 随机产生10个100-200之间的数 求最大值
VB 随机产生35个 20到80的随机整数