首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

帮小弟我看看代码哪出错了。关于子过程的

2012-01-26 
帮我看看代码哪出错了。关于子过程的。要求在TEXT1里输入一些英文。统计出每个字母出现了几次代码如下:Privat

帮我看看代码哪出错了。关于子过程的。
要求在TEXT1里输入一些英文。统计出每个字母出现了几次
代码如下:
Private Sub Command1_Click()
Dim str1 As String, a() As Integer
str1 = Text1.Text
ReDim a(26)
LCase (str1)
n = Len(str1)
Call CharCount(str1, a())
Picture1.Print "字母a出现了" & a(0) & "次"
Picture1.Print "字母b出现了" & a(1) & "次"
Picture1.Print "字母c出现了" & a(2) & "次"
Picture1.Print "字母d出现了" & a(3) & "次"

End Sub
Sub CharCount(str1 As String, a() As Integer)
Dim s()
s = Array(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
ReDim Preserve s(26)
For i = 1 To n
 For k = 0 To 25
  If Mid(str1, n, 1) = s(k) Then a(k) = a(k) + 1
 Next k
Next i
End Sub
运行了一下
为什么每次都是 字母a出现了0才,字母b出现了0次 其余都是0次。。。

[解决办法]

VB code
Private Sub Command1_Click()Dim str1 As String, a() As Integerstr1 = Text1.TextReDim a(26)LCase (str1)n = Len(str1)Call CharCount(str1, a())Picture1.Print "字母a出现了" & a(0) & "次"Picture1.Print "字母b出现了" & a(1) & "次"Picture1.Print "字母c出现了" & a(2) & "次"Picture1.Print "字母d出现了" & a(3) & "次"End SubSub CharCount(str1 As String, a() As Integer)Dim s()s = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")ReDim Preserve s(26)n = Len(str1)For i = 1 To n For k = 0 To 25  If Mid(str1, i, 1) = s(k) Then a(k) = a(k) + 1 Next kNext iEnd Sub 

热点排行