Home > Software engineering >  Please help to solve VB accumulation conditions of the code
Please help to solve VB accumulation conditions of the code

Time:10-29

As title, specific as follows:

MySQL database has a String of Data String has 99 cycle value (each value called the Data Line), and in each Data Line and the cycle of 10 5 groups, respectiely, in value (Code & amp; The Amount),

All 99 to realize is that the Data Line in the same Amount of Code that corresponds to the sum, and the output the same Code can only output one Line,

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

Implemented as a CAS * * 1 * 180 * 2 * 290 PR ~
CAS CO * * 45 * 420 * 223 * 580 ~
CAS CO * * 223 * 760 ~

I have used for intI... Next intI wrote, found that the two loop logic do not very understand, please everybody glad,

thank you

CodePudding user response:

Didn't understand the meaning of what the original poster said,

CodePudding user response:

The core part of this requirement is the data item summary accumulation, as for the original poster will PR1, PR2 again together into PR, such as 1, 2, and restructuring for the start of the CAS, can be the next step to do,

The simplest method is to use the ListBox list items to find and use a ItemData attributes (Long) for item by item, accumulation,
 
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 'precise search in the ListBox

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

List1. Clear
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))
The Else
List1. ItemData (n)=List1. ItemData (n) + Val (strItem (j + 1))
End the If
Next j
Next I

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

CodePudding user response:

Thank you for your answer, I'll try with your method,

CodePudding user response:

I use your code, but the pop-up variable not defined, is a List variable is not defined, please answer me why?

CodePudding user response:



He pulled a ListBox control on the Form

CodePudding user response:

Sorry, I am a rookie.

I think I don't need to explain in the List Box will be displayed, I need to realize the value of output in the TXT file above,

CodePudding user response:

Any player can pass the dictionary function to achieve the final result?

CodePudding user response:

refer to 7th floor markyao118 response:
is there a player can pass the dictionary function to achieve the final result?

The Dictionary is "object", not function,

  • Related