CodePudding user response:
A train of thought to youAs a first step, sorting, as to with what method you decide, what effervescent what binary way too much, not introduced,
The second step is to do a loop, the current one and one is the same as in the same group, a set of different,
CodePudding user response:
Form to add a ListBox, Sorted attribute set to True,Option Explicit
Private Declare Function SendMessagebyString Lib _
"User32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long As String)
Private Const LB_FINDSTRINGEXACT=& amp; H1A2
Private Sub Command1_Click ()
Dim strSource As String, strItem () As a String, As Long As Long, I n
,2,3,4,5,4,4,4,2,2,1,1,6 strSource="[1]"
StrSource=Replace (Replace (Replace (strSource, "/", "")," ", "")," ", "")
StrItem=Split (strSource, ", ")
List1. Clear
For I=0 To UBound (strItem)
N=SendMessagebyString (List1. HWND LB_FINDSTRINGEXACT, 1, strItem (I))
If n=1 Then
List1. AddItem strItem (I)
List1. ItemData (List1. NewIndex)=1
The Else
List1. ItemData (n)=List1. ItemData (n) + 1
End the If
Next I
ReDim strItem (List1. ListCount - 1)
For I=0 To List1. ListCount - 1
StrItem (I)="["
For n=1 To List1. ItemData (I) - 1
StrItem (I)=strItem (I) & amp; List1. List (I) & amp; ", "
The Next n
StrItem (I)=strItem (I) & amp; List1. List (I) & amp; "]
"The Debug. Print strItem (I)
Next I
The Debug. Print the Join (strItem, ", ")
End Sub
Results:
,1,1 [1]
,2,2 [2]
[3]
,4,4,4 [4]
[5]
[6]
,2,2,1,1 [1], [2], [3], [4,4,4,4], [5], [6]
CodePudding user response:
Option Explicit
'engineering reference: Microsoft Scripting Runtime
Private Type MembList
BuffSize As Long
MembNum As Long
DataBuff () As Long
End Type
Private Type GroupInfo
ListSize As Long
GroupNum As Long
GroupList () As MembList
End Type
'* * * press "subscript starting from 0" processing array * * *
Private stcDataGroup As GroupInfo 'grouping information management variable
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'* * will be a set of data grouping
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Private Sub Grouping (DataList () As Long)
Dim objDict As a Dictionary
Dim p As Long, n As Long, v As Long
Dim As Long I
'initialize grouping information
StcDataGroup. ListSize=16
StcDataGroup. GroupNum=0
ReDim stcDataGroup. GroupList (stcDataGroup. ListSize - 1)
'
start processing dataThe Set objDict=New Dictionary
For I=0 To UBound (DataList)
V=DataList (I)
If (objDict. The Exists (v)) Then
P=objDict. Item (v)
With stcDataGroup. GroupList (p)
P=. MembNum
If (p=. BuffSize) Then
N=p + 4 'most larger, extend the length of the list, if the list length YiQu slightly larger value,
ReDim Preserve. DataBuff (n - 1)
. BuffSize=n
End the If
DataBuff (p)=v
. MembNum=p + 1 '
End With
The Else
P=stcDataGroup. GroupNum
ObjDict. Add v p
'n=stcdatagroup. GroupList (p). MembNum
If (p=stcDataGroup. ListSize) Then 'add groups for
N=p + 8
'expansion of eight at a time, can according to your need to change, group number, YiQu slightly larger value,
'every time extension number is big, efficiency high,
StcDataGroup. ListSize=n
ReDim Preserve stcDataGroup. GroupList (n - 1)
End the If
'initialize new grouping
With stcDataGroup. GroupList (p)
N=16 'set the initial size in each group, packet length, is a larger value YiQu,
. BuffSize=n
ReDim. DataBuff (n - 1)
. MembNum=1
DataBuff (0)=v
End With
StcDataGroup. GroupNum=p + 1
End the If
Next
ObjDict. RemoveAll
End Sub
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'* * will be grouped data sample output (branch information obtaining sample)
'* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Private Sub ListGroup ()
Dim i& J&
For I=0 To stcDataGroup. GroupNum - 1
The Debug. Print "first" & amp; I + 1 & amp; "Set of data:
"For j=0 To stcDataGroup GroupList (I). MembNum - 1
The Debug. Print stcDataGroup. GroupList (I). DataBuff (j);
Next
The Debug. Print
Next
End Sub
Private Sub Command1_Click ()
Dim aData () As Long
Dim i& , sTxtBuf $()
,2,3,4,5,4,4,4,2,2,1,1,6 sTxtBuf=Split (" 1 ", ", ")
ReDim aData (UBound (sTxtBuf))
For I=0 To UBound (sTxtBuf)
AData (I)=sTxtBuf (I)
Next
Call the Grouping (aData) 'data packet
Call ListGroup 'output sample
End Sub
CodePudding user response:
Cattle are so many ha ha technology, DanielCodePudding user response:
Just suddenly thought of a problem, that is: "in each group, members are all the same",MembList as a result, the data type is not necessary to use an array to write to all members, as long as the record what value is, how many went,
Such a scheme, but also can simplify data management, and improve operational efficiency,
So my code can simplify:
Option Explicit
'engineering reference: Microsoft Scripting Runtime
Private Type MembList
MembNum As Long
The Value As Long
End Type
Private Type GroupInfo
ListSize As Long
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull