在线等,急需一个VB小程序,计算0-9数字总次数
请不要嫌我说得啰嗦,这也是为了节约您的时间:设计一个VB6小程序,在文本框输入或粘贴一段数字,有的数字后面带括号,且无论该小括号与前面的数字有多远,即使有换行,小括号内的...
请不要嫌我说得啰嗦,这也是为了节约您的时间:
设计一个VB6小程序,在文本框输入或粘贴一段数字,有的数字后面带括号,且无论该小括号与前面的数字有多远,即使有换行,小括号内的数字都属于左边离它最近的那串数字的次数,而数字后面没有小括号的要被视作有小括号,只不过里面的数字是1而已。注意小括号为英文输入法的小括号(),不是中文输入法的(),同时分开数字的逗号也是英文输入法下的。点击按钮后将所有数字的次数计算出来,生成.txt格式的文本弹出(即使用Shell "C:\WINDOWS\NOTEPAD.EXE " & App.Path & "\数字总次数.txt", 1),在文本内,数字的次数按从高到低顺序排列,次数一样的列在一起。下面的举例包含上面所说的所有情况:
2(6),08(4),15(3),9(2),36(说明:本列数字小括号内的数字全部紧跟左侧数字,2有6次,0和8 有4次,1和5都是3次,9是2次,3与6都是1次,7没出现)
9 (8),1 (7),23458 (5),0(4),6(说明:本列数字与次数有空格)
3(9),48(8),6
(7),5
(6),09(5),1(4),2(2)(说明:本列有换行,如6有7次,5有6次)
169(6),045(5),2(3),38(2)
则最终结果,在弹出的.txt文件中显示:
9(21),1(20),58(19),04(18),3(17),2(16),6(15),7(0),
注意上面的7没有出现,所以次数是0次,要求自己验证通过!不要错误的还发!!万分感谢。如果难以实现,我可以输入得规范些,如将1次的也带括号,前面的数字与后面的括号可以没有空格,但是换行是必要的。
怎么还没人回答啊,5555555555555555 展开
设计一个VB6小程序,在文本框输入或粘贴一段数字,有的数字后面带括号,且无论该小括号与前面的数字有多远,即使有换行,小括号内的数字都属于左边离它最近的那串数字的次数,而数字后面没有小括号的要被视作有小括号,只不过里面的数字是1而已。注意小括号为英文输入法的小括号(),不是中文输入法的(),同时分开数字的逗号也是英文输入法下的。点击按钮后将所有数字的次数计算出来,生成.txt格式的文本弹出(即使用Shell "C:\WINDOWS\NOTEPAD.EXE " & App.Path & "\数字总次数.txt", 1),在文本内,数字的次数按从高到低顺序排列,次数一样的列在一起。下面的举例包含上面所说的所有情况:
2(6),08(4),15(3),9(2),36(说明:本列数字小括号内的数字全部紧跟左侧数字,2有6次,0和8 有4次,1和5都是3次,9是2次,3与6都是1次,7没出现)
9 (8),1 (7),23458 (5),0(4),6(说明:本列数字与次数有空格)
3(9),48(8),6
(7),5
(6),09(5),1(4),2(2)(说明:本列有换行,如6有7次,5有6次)
169(6),045(5),2(3),38(2)
则最终结果,在弹出的.txt文件中显示:
9(21),1(20),58(19),04(18),3(17),2(16),6(15),7(0),
注意上面的7没有出现,所以次数是0次,要求自己验证通过!不要错误的还发!!万分感谢。如果难以实现,我可以输入得规范些,如将1次的也带括号,前面的数字与后面的括号可以没有空格,但是换行是必要的。
怎么还没人回答啊,5555555555555555 展开
1个回答
展开全部
这回完全符合你的题意了。
结果确实如你所给
新建一个exe工程,画一个text文本框,一个按钮。
text文本框的multiline=true
代码如下
'===========================
Option Explicit
Private Sub Command1_Click()
On Error GoTo writeFile:
Dim CacheA As String
Dim CacheB() As String
Dim CacheC() As String
Dim CounterA(0 To 9) As Long
Dim CounterCache(0 To 9) As Long
Dim ThisLenC As Long, LastLenC As Long
Dim i As Integer, j As Integer, b As Long, LastValue As Long, VBOut As String
CacheA = Text1.Text
CacheA = Replace(CacheA, Chr(32), "")
CacheA = Replace(CacheA, Chr(13), ",")
CacheA = Replace(CacheA, Chr(10), ",")
CacheA = Replace(CacheA, " ", "")
CacheA = Replace(CacheA, ")", Chr(35))
CacheA = Replace(CacheA, ",", Chr(35))
Do
CacheA = Replace(CacheA, Chr(35) & Chr(35), Chr(35))
Loop Until InStr(1, CacheA, Chr(35) & Chr(35), vbTextCompare) = 0
CacheA = Replace(CacheA, Chr(35) & "(", "(")
CacheB = Split(CacheA, Chr(35), , vbTextCompare)
For i = LBound(CacheB) To UBound(CacheB)
If InStr(1, CacheB(i), "(", vbTextCompare) = 0 Then
CacheB(i) = CacheB(i) & "(1"
End If
CacheC = Split(CacheB(i), "(", , vbTextCompare)
j = 0
Do While Len(CacheC(0)) > 0
LastLenC = Len(CacheC(0))
CacheC(0) = Replace(CacheC(0), j, "", , , vbTextCompare)
ThisLenC = Len(CacheC(0))
CounterA(j) = (LastLenC - ThisLenC) * CLng(CacheC(1)) + CounterA(j)
LastLenC = ThisLenC
j = j + 1
Loop
Next
For i = 0 To 9
CounterCache(i) = CounterA(i)
Next
For i = 0 To 9
For j = i + 1 To 9
If CounterCache(i) > CounterCache(j) Then
b = CounterCache(i)
CounterCache(i) = CounterCache(j)
CounterCache(j) = b
End If
Next
Next
LastValue = 0
For i = 9 To 0 Step -1
If Not LastValue = CounterCache(i) Then
For j = 0 To 9
If CounterA(j) = CounterCache(i) Then
VBOut = VBOut & j
End If
Next
VBOut = VBOut & "(" & CounterCache(i) & "),"
LastValue = CounterCache(i)
End If
Next
If FileLen(App.Path & "\数字总次数.txt") > 0 Then
Kill App.Path & "\数字总次数.txt"
End If
writeFile:
Open App.Path & "\数字总次数.txt" For Output As #1
Print #1, Left(VBOut, Len(VBOut))
Close #1
Shell "C:\WINDOWS\NOTEPAD.EXE " & App.Path & "\数字总次数.txt", 1
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
结果确实如你所给
新建一个exe工程,画一个text文本框,一个按钮。
text文本框的multiline=true
代码如下
'===========================
Option Explicit
Private Sub Command1_Click()
On Error GoTo writeFile:
Dim CacheA As String
Dim CacheB() As String
Dim CacheC() As String
Dim CounterA(0 To 9) As Long
Dim CounterCache(0 To 9) As Long
Dim ThisLenC As Long, LastLenC As Long
Dim i As Integer, j As Integer, b As Long, LastValue As Long, VBOut As String
CacheA = Text1.Text
CacheA = Replace(CacheA, Chr(32), "")
CacheA = Replace(CacheA, Chr(13), ",")
CacheA = Replace(CacheA, Chr(10), ",")
CacheA = Replace(CacheA, " ", "")
CacheA = Replace(CacheA, ")", Chr(35))
CacheA = Replace(CacheA, ",", Chr(35))
Do
CacheA = Replace(CacheA, Chr(35) & Chr(35), Chr(35))
Loop Until InStr(1, CacheA, Chr(35) & Chr(35), vbTextCompare) = 0
CacheA = Replace(CacheA, Chr(35) & "(", "(")
CacheB = Split(CacheA, Chr(35), , vbTextCompare)
For i = LBound(CacheB) To UBound(CacheB)
If InStr(1, CacheB(i), "(", vbTextCompare) = 0 Then
CacheB(i) = CacheB(i) & "(1"
End If
CacheC = Split(CacheB(i), "(", , vbTextCompare)
j = 0
Do While Len(CacheC(0)) > 0
LastLenC = Len(CacheC(0))
CacheC(0) = Replace(CacheC(0), j, "", , , vbTextCompare)
ThisLenC = Len(CacheC(0))
CounterA(j) = (LastLenC - ThisLenC) * CLng(CacheC(1)) + CounterA(j)
LastLenC = ThisLenC
j = j + 1
Loop
Next
For i = 0 To 9
CounterCache(i) = CounterA(i)
Next
For i = 0 To 9
For j = i + 1 To 9
If CounterCache(i) > CounterCache(j) Then
b = CounterCache(i)
CounterCache(i) = CounterCache(j)
CounterCache(j) = b
End If
Next
Next
LastValue = 0
For i = 9 To 0 Step -1
If Not LastValue = CounterCache(i) Then
For j = 0 To 9
If CounterA(j) = CounterCache(i) Then
VBOut = VBOut & j
End If
Next
VBOut = VBOut & "(" & CounterCache(i) & "),"
LastValue = CounterCache(i)
End If
Next
If FileLen(App.Path & "\数字总次数.txt") > 0 Then
Kill App.Path & "\数字总次数.txt"
End If
writeFile:
Open App.Path & "\数字总次数.txt" For Output As #1
Print #1, Left(VBOut, Len(VBOut))
Close #1
Shell "C:\WINDOWS\NOTEPAD.EXE " & App.Path & "\数字总次数.txt", 1
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub
参考资料: 终于改成了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询