VB单击Command1,随机生成100个大写英文字母存于数组a中,并显示在Text1中,字母之间用空格隔开

2024-12-02 05:38:31
推荐回答(2个)
回答(1):

Private Sub Command1_Click()
Dim a(99) As String, i As Integer
Randomize
For i = 0 To 99
a(i) = Chr(Asc("A") + Int(Rnd * 26))
Next
Text1.Text = Join(a, " ")
End Sub

回答(2):

这个问题有人问过了http://zhidao.baidu.com/question/538607993?&oldq=1
随机生成100个大写字母存于数组a中,并显示在text1中,字母间用空格隔开,在text2中输入一个大写字母,得出在数组a中出现的次数,在text3中显示。
Private arr(100)
Private Sub CommandButton1_Click()
Randomize
For i = 1 To 100
arr(i) = Chr(Int(Rnd * 26) + 65)
TextBox1.Text = TextBox1.Text & arr(i) & " "
Next
End Sub

Private Sub CommandButton2_Click()
Dim find As String
find = TextBox2.Text
TextBox3.Text = 0
For i = 1 To 100
If arr(i) = TextBox2.Text Then
TextBox3.Text = CInt(TextBox3.Text) + 1
End If
Next
End Sub