VB编程:用InputBox函数输入一个由数字0到9组成的字符串,统计其中每个数字出现的次数
2个回答
展开全部
Private Sub Command1_Click()
Dim s As String
Dim a(9) As Integer
s = InputBox("请输入数字字符串")
If IsNumeric(s) Then
For i = 1 To Len(s)
a(Mid(s, i, 1)) = a(Mid(s, i, 1)) + 1
Next i
Print "数字", "出现次数"
For i = 0 To UBound(a)
Print i, a(i)
Next i
Else
MsgBox "输入的字符不符合要求"
End If
End Sub
Dim s As String
Dim a(9) As Integer
s = InputBox("请输入数字字符串")
If IsNumeric(s) Then
For i = 1 To Len(s)
a(Mid(s, i, 1)) = a(Mid(s, i, 1)) + 1
Next i
Print "数字", "出现次数"
For i = 0 To UBound(a)
Print i, a(i)
Next i
Else
MsgBox "输入的字符不符合要求"
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询