Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Posts
    49

    Unanswered: addition in listbox

    List is like this in Listbox(Me.PalletIDOrTrackingNo_ListBox)

    LONO---|PalletNo|Description----------|BatchNO-|CRTN|Pcs|Total|Remain|Location
    ->1----|2-------|3-------------------|4---------|5---|6--|7----|8---|9--------


    ->7807 | 21102 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
    ->7807 | 21103 | DKNY BE DELICIOUS | 79658BV3 | 30 | 10 | 300 | 300 | 256BB
    ->7807 | 21104 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
    ->7808 | 21105 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD
    ->7808 | 21106 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD
    ->7807 | 21107 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
    ->7807 | 21108 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 | 256BA
    ->7808 | 21109 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 | 256BD

    How can I add selected items from column 8(Remain)?
    Like If I select first line then TotalRemain=200
    then If I select 2nd line then TotalRemain=200+300=500
    then If I select 3rd line then TotalRemain=200+300+200=700

    then If I disselect 2nd line then TotalRemain=200+300+200-300=400


    I am using this code but its not working properly

    For Each var In Me.PalletIDOrTrackingNo_Combo.ItemsSelected
    Me.TotalQuantity1 = Me.TotalQuantity1 + Me.PalletIDOrTrackingNo_Combo.Column(8, var)
    Next var

    using this code things gone like this

    Like If I selected first line then TotalRemain=200
    then If I select 2nd line then TotalRemain=200+200+300=700 instead of 200+300=500
    then If I select 3rd line then TotalRemain=200+200+300+300+200=1200 instead of 200+300+200=700

    I don't get it why this is happening but I think its bcz I am using FOR EACH.
    can anyone help me?

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Pseudo code
    Code:
    myTotal = 0
    
    For i = 0 To number of items in list (ListCount) - 1
        If mylistbox(i) is selected Then
            myTotal = myTotal + mylistbox(i), column 8.Value
        End If
    Next i
    George
    Home | Blog

  3. #3
    Join Date
    Dec 2007
    Posts
    49
    I am using this one but it showing error in line where I am using If()then

    Dim s As Integer

    For s = 0 To Me.PalletIDOrTrackingNo_ListBox.ListCount - 1
    If (Me.PalletIDOrTrackingNo_ListBox(s).ItemsSelected) Then
    Me.TotalQuantity1 = Me.TotalQuantity1 + Me.PalletIDOrTrackingNo_ListBox.Column(8, s)
    End If
    Next s

    how to write this line?

    If mylistbox(i) is selected Then 'in my case

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    Me.MyListBox.Selected(i)
    ??
    George
    Home | Blog

  5. #5
    Join Date
    Dec 2007
    Posts
    49
    I changed that line ,but this thing is doing the same thing as mine previous code.

    For Each var In Me.PalletIDOrTrackingNo_Combo.ItemsSelected

    Me.TotalQuantity1 = Me.TotalQuantity1 + Me.PalletIDOrTrackingNo_Combo.Column(8, var)

    Next var
    Last edited by billy_pit; 03-28-08 at 12:05.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •