求计算次数的VB代码

只对数字有效,对字母、标点符号无效。在VB生成的小程序的输入框中,任意输入或粘贴一段数字(有无空格均可),计算出0-9这十个数字出现的次数,并在点击“计算”按钮时,生成一... 只对数字有效,对字母、标点符号无效。在VB生成的小程序的输入框中,任意输入或粘贴一段数字(有无空格均可),计算出0-9这十个数字出现的次数,并在点击“计算”按钮时,生成一个txt文本(按“清除”按钮可以清空输入的数据)。例如输入1335637596712,按“计算”按钮时,生成一个txt文本,文本里按某个数字出现的次数多少依次显示,只有这种格式符合要求:
3(3),1567(2),29(1),048(0)
请大虾帮忙啊,急用!万分感谢!
不能用,自己不试试是否通过吗?连print都打成ptint。要立即弹出一个计算结果的文本,这些代码未能实现
展开
 我来答
棘棘芽
2010-07-25 · TA获得超过563个赞
知道小有建树答主
回答量:608
采纳率:100%
帮助的人:555万
展开全部
这个用用吧!
Private Sub command1_click()
Dim s As String
s = Text1.Text '这里就算是你的文本框了
Dim i As Integer, temp As String
Dim by(0 To 9) As Long
For i = 1 To Len(s)
temp = Mid(s, i, 1)
Select Case Asc(temp)
Case 48 To 58
by(Asc(temp) - 48) = by(Asc(temp) - 48) + 1
End Select
Next
s = ""
Dim z As Integer, b As Boolean
For i = 0 To 9
For j = 0 To 9
If by(j) = i Then
s = s & Chr(48 + j)
z = z + 1
b = True
End If
Next
If b Then s = s & "(" & i & "),"
b = False
z = 0
Next
s = Left(s, Len(s) - 1)
If Len(Dir(App.Path & "\temp.txt")) Then Kill App.Path & "\temp.txt"
Open App.Path & "\temp.txt" For Output As #1
print #1, s
Close #1
msgbox s
End Sub
出了点错,改下!本来用的write 写入的再"",就改了下!打错了!
上面的s主是你要的数据!你的文本我不知道你说的是文本框,还是记事本!只写成了这样!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
烟花坑zZ
2010-07-23 · TA获得超过1196个赞
知道小有建树答主
回答量:542
采纳率:0%
帮助的人:751万
展开全部
'正解如下!
'‘***************************************************
Private Sub command1_click()
Dim s As String
s = Text1.Text
Dim i As Integer, temp As String
Dim by(0 To 9) As Long
For i = 1 To Len(s)
temp = Mid(s, i, 1)
Select Case Asc(temp)
Case 48 To 57
by(Asc(temp) - 48) = by(Asc(temp) - 48) + 1
End Select
Next
s = ""
Dim z As Integer, b As Boolean
For i = 0 To 9
For j = 0 To 9
If by(j) = i Then
s = s & Chr(48 + j)
z = z + 1
b = True
End If
Next
If b Then s = s & "(" & i & "),"
b = False
z = 0
Next
s = Left(s, Len(s) - 1)
q = Split(s, ",")
s = ""
For i = UBound(q) To LBound(q) Step -1
s = s & q(i) & ","
Next
Open App.Path & "\temp.txt" For Output As #1
Print #1, s
Close #1
Shell "C:\WINDOWS\NOTEPAD.EXE " & App.Path & "\temp.txt ", 1
End Sub
'‘***************************************************
已经修改
已经修改
已经修改
已经修改
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
tianjinfan2
2010-07-27 · TA获得超过280个赞
知道小有建树答主
回答量:129
采纳率:0%
帮助的人:88.1万
展开全部
我写个简单点的,弄一个textbox控件和一个command控件
Private Sub Command1_Click()
Dim a(9) As Integer
Dim b(9) As String
txt = Trim(Text1.Text)
For i = 1 To Len(txt)
x = Mid(txt, i, 1)
If Asc(x) > 47 And Asc(x) < 58 Then
Select Case Asc(x) - 48
Case 0
a(0) = a(0) + 1
Case 1
a(1) = a(1) + 1
Case 2
a(2) = a(2) + 1
Case 3
a(3) = a(3) + 1
Case 4
a(4) = a(4) + 1
Case 5
a(5) = a(5) + 1
Case 6
a(6) = a(6) + 1
Case 7
a(7) = a(7) + 1
Case 8
a(8) = a(8) + 1
Case 9
a(9) = a(9) + 1
End Select
End If
Next i
For i = 0 To 9
If a(i) = 0 Then b(0) = b(0) & i
If a(i) = 1 Then b(1) = b(1) & i
If a(i) = 2 Then b(2) = b(2) & i
If a(i) = 3 Then b(3) = b(3) & i
If a(i) = 4 Then b(4) = b(4) & i
If a(i) = 5 Then b(5) = b(5) & i
If a(i) = 6 Then b(6) = b(6) & i
If a(i) = 7 Then b(7) = b(7) & i
If a(i) = 8 Then b(8) = b(8) & i
If a(i) = 9 Then b(9) = b(9) & i
Next i
Open "E:\d.txt" For Output As #1
For i = 0 To 9
If b(i) <> "" Then Print #1, b(i); "("; i; ")"; ",";
Next i
Close #1
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友aa1a393ac
2010-07-24 · TA获得超过220个赞
知道小有建树答主
回答量:421
采纳率:33%
帮助的人:368万
展开全部
Private Sub Command1_Click()
Dim i As Integer, j As Integer, myD(9) As Integer, myMax As Integer, myOutput As String, myOk As Boolean
For i = 0 To 9
myD(i) = Len(Text1.Text) - Len(Replace(Text1.Text, i, ""))
If myD(i) > myMax Then myMax = myD(i)
Next
For i = myMax To 0 Step -1
For j = 0 To 9
If myD(j) = i Then myOutput = myOutput & j: myOk = True
Next
If myOk = True Then myOutput = myOutput & "(" & i & "),"
myOk = False
Next
Open App.Path & "\统计数字个数.txt" For Output As #1
Print #1, myOutput
Close
Shell "C:\WINDOWS\NOTEPAD.EXE " & App.Path & "\统计数字个数.txt", 1
End Sub
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zxyzxy12321
2010-07-23 · TA获得超过1211个赞
知道小有建树答主
回答量:800
采纳率:100%
帮助的人:0
展开全部
没有看懂lz的意思
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式