要求实现排序功能, 先号*号前面的数字按升序排列,然后按*号后面的数字按升序排序
后缀字母(一位或两位)忽略不计。
例:要求这样:
1*110
1*220
12*10
13*210
13*230
14*1
14*10
14*11f
14*12谢谢。
后缀字母(一位或两位)忽略不计。
例:要求这样:
1*110
1*220
12*10
13*210
13*230
14*1
14*10
14*11f
14*12谢谢。
解决方案 »
- EXCEL 执行慢的问题
- 问一个弱智问题,钢是有磁性的吗?
- 在MSHFlexGrid中确定鼠标选择的CELL区域?
- 如何实现DATAGRID和COMBO的结合?
- 关于打包问题的疑惑...
- MsgBox (msgPrompt,vbExclamation )为什么错了?
- 如何访问远程数据库(在线等待)
- 请问:怎样修改菜单的字体大小和调整不同菜单的间距???
- 如何对二进制文件进行修改,急在线等待
- 有一个窗体,该窗体上有一个commondbutton控件,要不显示该窗体,程序触发该窗体上commondbutton控件的click事件。我用 load frm1 frm1.cmd1_click 为什么不行?
- 对不住各位英雄了。惨就一个字啊
- vb写的com+在win2000下注册后运行正常,但是在win2003上注册以后,根本无法运行,请问是什么原因呢?
你可以关注此贴的讨论:http://community.csdn.net/Expert/topic/3214/3214394.xml?temp=.6535608
然后用一个循环找出前面数字相同的项,分批排序具体就不写了
Dim ar(20, 250) As String
str = Array("13*230", "14*1", "14*10", "1*110", "1*220", "12*10", "13*210", "14*11", "14*12")
Dim i As Integer
Dim a As Integer, b As Integer
Dim ins As Integer
For i = 0 To UBound(str)
ins = VBA.InStr(str(i), "*")
a = Left(str(i), ins - 1)
b = Right(str(i), Len(str(i)) - ins)
ar(a, b) = str(i)
Next i
For a = 0 To 20
For b = 0 To 250
If ar(a, b) <> vbNullString Then
MsgBox ar(a, b)
End If
Next
Next
而后面的数字做为后层节点,排序结果如下
+1
-----110
-----220
+12
------110
+13
-----210
-----230
+144
------1
------10
------11
------12
这样做的目的纯粹是为了好玩,建议实际做时用字典,再在排序算法上做优化
Private Sub Command4_Click()
Dim str
str = Array("13*230", "14*1", "14*10", "1*110", "1*220", "12*10", "13*210", "14*11", "14*12")
Dim i As Integer
Dim a As Integer, b As Integer
Dim ins As Integer
Dim NodX As Node
Dim NodTemp As Node
Dim NodSecond As Node
Dim N As Integer
TreeView1.Nodes.Add , , "Root", "根目录"
For i = LBound(str) To UBound(str)
With TreeView1
ins = VBA.InStr(str(i), "*")
a = Left(str(i), ins - 1)
b = Right(str(i), Len(str(i)) - ins)
If (.Nodes(1).Children > 0) Then
Set NodTemp = .Nodes("Root").Child '在第一层按前面的数字排序
N = NodTemp.FirstSibling.Index '取到第一个节点
Do While (N <> NodTemp.LastSibling.Index)
If (a < CInt(Right(.Nodes(N).Key, Len(.Nodes(N).Key) - 1))) Then
'在该节点之前
Set NodX = .Nodes.Add(.Nodes(N), tvwPrevious, "N" & a, CStr(a))
.Nodes.Add .Nodes(NodX.Index), tvwChild, , CStr(b)
Exit Do
ElseIf (a = CInt(Right(.Nodes(N).Key, Len(.Nodes(N).Key) - 1))) Then
Set NodSecond = .Nodes("N" & a).Child
N = NodSecond.FirstSibling.Index '取到第一个节点
Do While (N <> NodSecond.LastSibling.Index)
If (b < CInt(.Nodes(N).Text)) Then
'在该节点之前
.Nodes.Add .Nodes(N), tvwPrevious, , CStr(b)
Exit Do
End If
N = .Nodes(N).Next.Index
Loop
If (N = NodSecond.LastSibling.Index) Then
If (b < .Nodes(N).Text) Then
.Nodes.Add .Nodes(N), tvwPrevious, , CStr(b)
Else
.Nodes.Add .Nodes(N), tvwNext, , CStr(b) '插在最后
End If
End If
Exit Do
End If
N = .Nodes(N).Next.Index
Loop
If (N = NodTemp.LastSibling.Index) Then
If (a < CInt(Right(.Nodes(N).Key, Len(.Nodes(N).Key) - 1))) Then
Set NodX = .Nodes.Add(.Nodes(N), tvwPrevious, "N" & a, CStr(a))
.Nodes.Add .Nodes(NodX.Index), tvwChild, , CStr(b)
ElseIf (a = CInt(Right(.Nodes(N).Key, Len(.Nodes(N).Key) - 1))) Then
Set NodSecond = .Nodes("N" & a).Child
N = NodSecond.FirstSibling.Index '取到第一个节点
Do While (N <> NodSecond.LastSibling.Index)
If (b < CInt(.Nodes(N).Text)) Then
'在该节点之前
.Nodes.Add .Nodes(N), tvwPrevious, , CStr(b)
Exit Do
End If
N = .Nodes(N).Next.Index
Loop
If (N = NodSecond.LastSibling.Index) Then
If (b < .Nodes(N).Text) Then
.Nodes.Add .Nodes(N), tvwPrevious, , CStr(b)
Else
.Nodes.Add .Nodes(N), tvwNext, , CStr(b) '插在最后
End If
End If
Else
Set NodX = .Nodes.Add(.Nodes(N), tvwNext, "N" & a, CStr(a)) '插在最后
.Nodes.Add .Nodes(NodX.Index), tvwChild, , CStr(b)
End If
End If
Else
Set NodX = .Nodes.Add("Root", tvwChild, "N" & a, CStr(a))
.Nodes.Add .Nodes(NodX.Index), tvwChild, , CStr(b)
End If
End WithNext i
End Sub