Please help to solve the conditions in VB cumulative code

Such as the title, as follows:

The MySQL database has a Data String 99 cycle value (each value is called Data Line), and in each of the Data Line and the 10 values were 5 groups of cycle value(Code & Amount).

To realize is, the corresponding to all 99 Data Line within the same Code Amount are accumulated, and output a line in the output of the same Code only.

Such as: DataLine1 in front of some useless string, PR1, 100, PR2, 200, CO45, 300, CO223, 400, OAB5, 500 data between Chr (240) separated
DataLine2 in front of some useless string, PR1, 80, PR2, 90, CO45, 120, CO223, 180, OAB5, 260 data between Chr (240) separated

Implementation for CAS*PR*1*180*2*290~

I have used a for intI... Next intI wrote, and found that the 2 loop within the logic do not quite understand, please master generous with your criticism.

Thank you.

Started by Fabian at February 05, 2016 - 12:32 PM

I don't understand what you say.

Posted by Jacqueline at February 14, 2016 - 12:40 PM

The core part of this demand is the data item summary accumulation. The landlord will PR1, PR2 and then aggregated into PR, 1,2 and recombinant CAS initial series, can do that next.

The most simple method is to use the list items to find the ListBox and ItemData attributes (type Long) one accumulation.

Private Declare Function SendMessagebyString Lib _
"user32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long

Private Const LB_FINDSTRINGEXACT = &H1A2 'Exact search in ListBox

Private Sub Command1_Click()
Dim i As Long, j As Long, n As Long
Dim strItem() As String

For i = 1 To 99
strItem = Split(Data_Line(i), ",")
For j = 0 To 8 Step 2
strItem(j) = Trim(Item(j))
strItem(j + 1) = Trim(Item(j + 1))
n = SendMessagebyString(List1.hWnd, LB_FINDSTRINGEXACT, -1, strItem(j))

If n = -1 Then
List1.AddItem strItem(j)
List1.ItemData(List1.NewItem) = Val(strItem(j + 1))
List1.ItemData(n) = List1.ItemData(n) + Val(strItem(j + 1))
End If
Next j
Next i

For i = 0 To List1.ListCount - 1
Debug.Print List1.List(i), List1.ItemData(i)
Next i
End Sub

Posted by Lucia at February 21, 2016 - 1:33 PM

Thank you to answer, I'll try your method.

Posted by Fabian at February 24, 2016 - 2:25 PM

I use your code, but pop variable not defined, is the List variable not defined. Please explain why?

Posted by Fabian at December 16, 2016 - 9:42 AM

You drag a ListBox control to the Form.

Posted by Dylan at December 18, 2016 - 10:33 AM

Feel shy, I was a rookie.

I want to explain what I do not need to display in the List Box, I need to achieve the above the value of output in the txt file.

Posted by Fabian at December 28, 2016 - 11:03 AM

There is no master can through the dictionary function to achieve the final result?

Posted by Fabian at January 11, 2017 - 11:33 AM

Dictionary is the "object", not a function.

Posted by Jacqueline at January 15, 2017 - 11:56 AM