求VB高手编一程序

来源:百度知道 编辑:UC知道 时间:2024/09/20 14:25:14
声明一个有20个元素的一维字符类型数组,要求:
1、由随机数形成小写字母构成的数组,每个元素的字符个数由随机数产生,范围1-11。
2、要求将生成的数组分四行显示。
3、显示生成的字符数组中字符最多的元素。

Private Sub Form_Click()
Dim zfc(1 To 20) As String, n As Integer, nmax As Integer
Randomize
Cls
nmax = 0
For i = 1 To 20
n = 1 + Int(11 * Rnd)

For j = 1 To n
zfc(i) = zfc(i) & Mid("abcdefghijklmnopqrstuvwxyz", 1 + Int(26 * Rnd), 1)
Next
Print zfc(i),
If i Mod 5 = 0 Then Print
If n > nmax Then nmax = n
Next

Print
Print "字符最多的元素是:"
For i = 1 To 20
If Len(zfc(i)) = nmax Then Print "第" & i & "个", zfc(i)
Next

End Sub