当我卖一个商品的同时`就会检查一下货品号`如果相同就在原来的基础上加1
如果不同就列出这个商品的信息`请问这个累计是怎么写的`

解决方案 »

  1.   

    你肯定有这笔账开始的第一个值,从第一个商品开始建立二维数组
    arr(0 to 1,) as string
    一维放条形码,一维放数量,新货要到数组里面搜寻一下,如果找到相同条形码就再数量上面+1,如果没找到,就添加在数组中。最后结算就好了就是这逻辑了,你看看
      

  2.   

    Dim a(), tmp, i, j
    Private Sub Command1_Click()
    tmp = Text1
    For i = 1 To UBound(a, 2)
        If a(1, i) = tmp Then a(2, i) = a(2, i) + 1: Exit For
    Next
    If i > UBound(a, 2) Then
        ReDim Preserve a(2, UBound(a, 2) + 1)
        a(1, UBound(a, 2)) = tmp
        a(2, UBound(a, 2)) = 1
    End IfFor i = 1 To UBound(a, 2)
        For j = 1 To 2
            Debug.Print a(j, i);
        Next: Debug.Print
    Next
    End Sub
    Private Sub Form_Load()
    ReDim a(2, 0)
    End Sub
      

  3.   

    如果我想取a(j,i)里的I 是不是ubound(a,2)
      

  4.   

    如果不用数组,你从哪里比较barcode又在哪里+1呢?我来写一个希望有帮助dim arrProduct(,) as integer '低维存barcode,高维存数量Private Sub Command1_Click() '模拟你的扫描器扫描结束一个货品
      dim i as integer,j as integer,bRt as boolean
      j=ubound(arrProduct,2)
      for i=0 to  j'在存在数组中查找
       if text1.text=arrProduct(0,i) then
         arrProduct(1,i)=arrProduct(1,i)+1
         bRt=true
         exit for
       end if
       if bRt=false then  '--数组中不存在
         Redim Preserve arrProduct(0 to 1,j+1)
         arrProduct(0,j+1)=text1.text
         arrProduct(1,j+1)=1
       end if
      next iend sub等到结算很容易就找到总价格了
      

  5.   

    Redim Preserve arrProduct(0 to 1,j+1)
    是什么意思`
      

  6.   

    你查查Redim Preserve就全都知道了用google,baidu都好,最不济还有msdn
      

  7.   

    Dim a(), tmp, i, j
    Private Sub Command1_Click()
    tmp = Text1
    For i = 1 To UBound(a, 2)
        If a(1, i) = tmp Then a(2, i) = a(2, i) + 1: Exit For
    Next
    If i > UBound(a, 2) Then
        ReDim Preserve a(2, UBound(a, 2) + 1)
        a(1, UBound(a, 2)) = tmp
        a(2, UBound(a, 2)) = 1
    End IfFor i = 1 To UBound(a, 2)
        For j = 1 To 2
            Debug.Print a(j, i);
        Next: Debug.Print
    Next
    End Sub
    Private Sub Form_Load()
    ReDim a(2, 0)
    End Sub
    对于这个函数`
    只要它保存在数组中`
    不须要输出的话!
    那应该怎么写`
      

  8.   

    Dim a(), tmp, i, j
    Private Sub Command1_Click()
    tmp = Text1
    For i = 1 To UBound(a, 2)
    If a(1, i) = tmp Then a(2, i) = a(2, i) + 1: Exit For
    Next
    If i > UBound(a, 2) Then
    ReDim Preserve a(2, UBound(a, 2) + 1)
    a(1, UBound(a, 2)) = tmp
    a(2, UBound(a, 2)) = 1
    End If
    end subPrivate Sub Form_Load()
    ReDim a(2, 0)
    End Sub