2 Attachment(s)
cashier program, update that array
I have write cashier program, now question,
i'm sorry, I can't clear my problem.
I try sound:
step:
product code "402" first scan, qty x1
this is build one elem.
again, code "407" scan, qty x1
this is build 2 elem.
again, code "402" scan, qty x7
this is build 3 elem.
you can see List4, List5
is correct show,
402 = 2 record
407 = 1 record
but I hope changed:
402 = 8 record
407 = 4 record.
hope you understand it.
you can see my full code in attached (RAR format)
Re: cashier program, update that array
I think In here, how To (qty + group count) = finial qty ?
Code:
Private Sub sh_Click()
Dim i As Long
List3.Clear
For i = LBound(R, 2) To UBound(R, 2)
'(0)=barcode , (1)=qty, (2)=amount
List3.AddItem R(0, i) & ">" & R(1, i) & ">" & R(2, i)
Next i
Call grouptype(R)
End Sub
Code:
Option Explicit
'thanks: spoo
'http://www.vbforums.com/showthread.php?t=617320
Public Function grouptype(ByRef tmpR() As String)
Form1.List4.Clear
Form1.List5.Clear
' 1. count unique occurrences
Dim nn As Integer
Dim txt As String
Dim delim As String
Dim ii As Integer
Dim tt As String
Dim v1 As String
nn = 0 ' counter
txt = ""
delim = "+" ' pick something that won't be in List1
For ii = LBound(tmpR, 2) To UBound(tmpR, 2)
tt = tmpR(0, ii)
v1 = InStr(txt, tt)
If v1 = 0 Then
txt = txt + tt + delim
nn = nn + 1
End If
Next ii
'////////////////////////////////////////////////
' 2. dim the array
Dim aTYPE()
ReDim aTYPE(nn, 2)
'
' eg: aType(1, 1) = "a" ' 1. the type
' aType(1, 2) = 3 ' 2. num of occurences
'
' 3. shake out results into array
Dim mxln As Integer
Dim txt1 As String
Dim xtr As String
Dim lnxtr As Integer
mxln = 0
txt1 = txt
For ii = 1 To nn
' find end of this "type" -- using the delimiter
v1 = InStr(txt1, delim)
xtr = Mid(txt1, 1, v1 - 1) ' extract text up to the delimiter
aTYPE(ii, 1) = xtr ' assign extracted text to array
' "remove" this "type" from string
txt1 = Mid(txt1, v1 + 1)
' update max length (used below -- for display purposes only)
lnxtr = Len(xtr)
mxln = IIf(lnxtr > mxln, lnxtr, mxln)
Next ii
' 4. go thru list1 again, populate with num of occurrences
Dim jj As Integer
For ii = LBound(tmpR, 2) To UBound(tmpR, 2)
tt = tmpR(0, ii)
For jj = 1 To nn
If aTYPE(jj, 1) = tt Then
aTYPE(jj, 2) = aTYPE(jj, 2) + 1
Exit For
End If
Next jj
Next ii
' 5. display in list2
Dim pp As Integer
For ii = 1 To nn
' determine "pad" needed -- to align the ct's
lnxtr = Len(aTYPE(ii, 1))
pp = mxln - lnxtr
' create string for List
Form1.List4.AddItem aTYPE(ii, 1)
Form1.List5.AddItem Trim(aTYPE(ii, 2))
Next ii
End Function