Home > Software engineering >  Read a excel file from the vb, the separation of string, and do judgment processing, algorithm idea
Read a excel file from the vb, the separation of string, and do judgment processing, algorithm idea

Time:10-29

I read in the vb a excel file, the excel file is composed of a number of rows and columns, one line of data is this:
(1) x 1 a, 2 b x
(2) 1 x b
(3) 2 x a
(4) 1 x a
(5) 1 x c
(6) 1 x b
(7) 1 x c, 1 x b
.
Number of rows, the columns of data, 1 x represents a items have a 1 piece, there may be multiple varieties in the same line, such as the first lines (1) and (7), is now asking is this: when reading a line, separate the items and quantity, number of inventory is corresponding to the items in the database, for example: if the item a surplus inventory number 3, b remaining inventory number four, C surplus inventory number 2, then according to the requirements, the first line (1) is ok, also can be the first (2), the first line (3), can also be the first line (4) no, the first line (5) can, the first line (6) can be, the first (7) no, because the number of the first line (7) C is satisfied, but b of the inventory has been insufficient, so can't, on the can and can't, in the judgment to the cell in a row column mark yes or no,
I already do, read in excel, separate items and quantity, if from each operation in the database, inefficient back and forth, speaking, reading and writing. If you want to make as little as possible to access the database, and on how to solve, 1 x a, each reading a line, isolated x in front of the Numbers, as to the next line, continue to,

CodePudding user response:

To analyze your sample database to read first, get the following data
Array=3 (a)
Array=4 (b)
Array (c)=2
"'" '
After reading the first line
Array (a)=2=3-1
Array (b)=4-2=2
Array (c)=2
After reading the second line
Array=2 (a)
Array (b)=2-1=1
Array (c)=2
After reading the third line
Array (a)=2-2=0
Array (b)=1
Array (c)=2
After reading the fourth row
Array (a)=0 & lt; 1 failure
Array (b)=1
Array (c)=2
.
.

CodePudding user response:

Is there a viable way,

CodePudding user response:

Using the Split function?

CodePudding user response:

Please provide better solution,
My test code:
 Private Sub TestNewFunction0805 () 
Dim strCustomer strOrisku, strDestsku As String
Dim nRows, cntskus isku2stock, isumsku As Integer
Dim nCurskuNum TMPJ, TMPK As Integer
Dim i1, i2, i3, i2 As Integer
Dim phbz1, phbz2 As String
NRows=CountMsflexgirdRows
For i1=1 To nRows - 1
Phbz1=MSFG. TextMatrix (i1, 10)
Phbz2=MSFG. TextMatrix (i1, 11)
StrCustomer=MSFG. TextMatrix (i1, 12)
Cntskus=SplitTestSKU (phbz1)
For i2=0 To cntskus - 1
StrOrisku=Sp (i2, 0)
Isumsku=CInt (Sp (i2, 1))
Isku2stock=GetStockNumBySKUAndOwner (strOrisku, strCustomer) 'access to inventory quantity function
If isku2stock=1 Then
MSFG. TextMatrix (i1, 14)="no"
GoTo exiti1
The Else
MSFG. TextMatrix (i1, 14)="yes"
Isku2stock=isku2stock - isumsku
End the If
For i3=i1 + 1 To nRows - 1
NCurskuNum=SplitTestInterSKU (MSFG TextMatrix (i3, 10))
For i2=0 To nCurskuNum - 1
If strOrisku=Spin (i2, 0) Then
Isku2stock=isku2stock - CInt (Spin (i2, 1))
End the If
If isku2stock & gt;=0 Then
MSFG. TextMatrix (i3, 14) marked as invalid order="yes" '
The Else
MSFG. TextMatrix (i3, 14)="no" to continue processing
GoTo exiti1
End the If
Next i4
For TMPJ=0 To 9
Spin (TMPJ, 0)=""
Spin (TMPJ, 1)=""
Next TMPJ
Next i3
Next i2
For TMPK=0 To 9
Sp (TMPK, 0)=""
Sp (TMPK, 1)=""
Next TMPK
Exiti1:
Next i1
End Sub

CodePudding user response:

Please continue to give directions!

CodePudding user response:

2 floor feasibility, first read the inventory from a database, and then memory processing line by line,

CodePudding user response:

Reference:
 
Private Sub Command1_Click ()
Dim dic As Object, arr, BRR () As String, v () As the String, t () As String, I As Long, j As Long
The Set dic=CreateObject (" scripting. The dictionary ")
Dic (" a ")=3
Dic (" b ")=4
Dic (" c ")=2
Arr=Array (" 1 x a, 2 x b ", "b" 1 x, 2 x "a", "1 x a", "1 x c", "1 x b", "1 x 1 x c, b)
ReDim BRR (UBound (arr))
For I=0 To UBound (arr)
V=Split (arr (I), ", ")
BRR (I)=True
For j=0 To UBound (v)
T=Split (v (j), "x")
BRR (I)=BRR (I) And (Val (Trim (t (0))) & lt;=dic (Trim (t (1))))
Dic (Trim (t) (1))=dic (Trim (t (1))) - Val (Trim (t (0)))
Next
Next
MsgBox Join (BRR, ", ")
End Sub
  • Related