题型:综合题 题类:常考题 难易度:普通
浙江省高中信息技术 过程与自定义函数同步练习
实现上述功能的VB程序如下,请在划线处填入合适的代码。
Private Sub Command1_Click()
Dim a(1 To 10) As Integer ‘存储0~9每个数字出现的次数
Dim b(1 To 26) As Integer ‘存储a~z每个字母出现的次数
Dim zf As String, x As String, p As Integer
Dim maxa As Integer, maxb As Integer
For i = 1 To Len(zf)
x = Mid(zf, i, 1)
If pd(x) = 1 Then
p = Asc(x) - Asc(“0”) + 1
a(p) = a(p) + 1
p = Asc(x) - Asc(“A”) + 1
b(p) = b(p) + 1
Else
p = Asc(x) - Asc(“a”) + 1
b(p) = b(p) + 1
End If
Next i
k = a(1):maxa = 1
For i = 2 To 10
If a(i) > k Then k = a(i):maxa = i
Next i
k = b(1) :maxb = 1
For i = 2 To 26
IfThen k = b(i) :maxb = i
Next i
Label1.Caption =“出现最多的数字是” + Chr(maxa+ Asc(“0”)-1)
Label2.Caption = “出现最多的字母是” + Chr(maxb + Asc(“A”)-1)
End Sub
Function pd(ch As String) As Integer ’函数用于判断每个字符类型
If ch >= “0” And ch <= “9” Then pd = 2
If ch >= “A” And ch <= “Z” Then pd = 2
If ch >= “a” And ch <= “z” Then pd = 3
End Function
试题篮