VB 输入一串字符,统计各字母出现的次数(大小写字母不区分)。 Private Sub Command1_Click()
输入一串字符,统计各字母出现的次数(大小写字母不区分)。PrivateSubCommand1_Click()DimcAsString,x%,a(1To26)AsInteg...
输入一串字符,统计各字母出现的次数(大小写字母不区分)。
Private Sub Command1_Click()
Dim c As String, x%, a(1 To 26) As Integer
For i = 1 To Len(Text1.Text)
c = UCase(Mid(Text1.Text, i, 1))
If c >= "A" And c <= "Z" Then
j = Asc(c) - 64
a(j) = a(j) + 1
End If
Next i
For j = 1 To 26
Picture1.Print Chr(j + 64) & "=" & "a(j)";
Next j
End Sub
为什么运行后不输入任何东西和输入字母的效果都是A=a(j)B=a(j)...Z=a(j) 展开
Private Sub Command1_Click()
Dim c As String, x%, a(1 To 26) As Integer
For i = 1 To Len(Text1.Text)
c = UCase(Mid(Text1.Text, i, 1))
If c >= "A" And c <= "Z" Then
j = Asc(c) - 64
a(j) = a(j) + 1
End If
Next i
For j = 1 To 26
Picture1.Print Chr(j + 64) & "=" & "a(j)";
Next j
End Sub
为什么运行后不输入任何东西和输入字母的效果都是A=a(j)B=a(j)...Z=a(j) 展开
展开全部
Picture1.Print Chr(j + 64) & "=" & "a(j)";中a(j)是不要加“”的,否则就变成了字符串了,还有在picturebox里打印时最好换行,不要打印在一行上,太长了,所以,建议你把后面冒号也去掉,如下:
Private Sub Command1_Click()
Dim c As String, x%, a(1 To 26) As Integer
For i = 1 To Len(Text1.Text)
c = UCase(Mid(Text1.Text, i, 1))
If c >= "A" And c <= "Z" Then
j = Asc(c) - 64
a(j) = a(j) + 1
End If
Next i
For j = 1 To 26
Picture1.Print Chr(j + 64) & "=" & a(j)
Next j
End Sub
Private Sub Command1_Click()
Dim c As String, x%, a(1 To 26) As Integer
For i = 1 To Len(Text1.Text)
c = UCase(Mid(Text1.Text, i, 1))
If c >= "A" And c <= "Z" Then
j = Asc(c) - 64
a(j) = a(j) + 1
End If
Next i
For j = 1 To 26
Picture1.Print Chr(j + 64) & "=" & a(j)
Next j
End Sub
追问
嗯,那一开始为什么不用声明a(j)=0?
追答
因为数组在没有赋值的情况下,系统默认为0,所以不用声明a(j)=0的。
展开全部
只要吧Picture1.Print Chr(j + 64) & "=" & "a(j)";改为Picture1.Print Chr(j + 64) & "=" & a(j);就行了。
Private Sub Command1_Click()
Dim c As String, x%, a(1 To 26) As Integer
Picture1.Cls
For i = 1 To Len(Text1.Text)
c = UCase(Mid(Text1.Text, i, 1))
If c >= "A" And c <= "Z" Then
j = Asc(c) - 64
a(j) = a(j) + 1
End If
Next i
For j = 1 To 26
If j Mod 6 = 0 Then
Picture1.Print Chr(j + 64) & "=" & a(j)
Picture1.Print
Else
Picture1.Print Chr(j + 64) & "=" & a(j);
Picture1.Print Space(3);
End If
Next j
End Sub
Private Sub Command1_Click()
Dim c As String, x%, a(1 To 26) As Integer
Picture1.Cls
For i = 1 To Len(Text1.Text)
c = UCase(Mid(Text1.Text, i, 1))
If c >= "A" And c <= "Z" Then
j = Asc(c) - 64
a(j) = a(j) + 1
End If
Next i
For j = 1 To 26
If j Mod 6 = 0 Then
Picture1.Print Chr(j + 64) & "=" & a(j)
Picture1.Print
Else
Picture1.Print Chr(j + 64) & "=" & a(j);
Picture1.Print Space(3);
End If
Next j
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询