Calculating non numeric in listbox

hi,
I was trying to count the total if rom labeled ‘open’ with this code,

dim row as integer dim totald as double for row= 0 to CustomersList1.ListCount-1 if CustomersList1.cell(row,6)="open" then totald = totald + val(CustomersList1.Cell(row, 6)) end if next t_open.text=str(totald)

I dont know why the result is 0.

Any Helps.?

Thanks
Regards,
Rivo

[quote=21220:@Rivo]if CustomersList1.cell(row,6)=“open” then
totald = totald + val(CustomersList1.Cell(row, 6))[/quote]

At first glance, this is your problem. If cell(row, 6) = “open” then it’s value will be zero when converted to a number as it’s not a number.

Perhaps you meant for the second line to total up a different column?

yes, the problem is, I want to calculate on the same column,
calculating on different column is my last option.
if its not possible to do it, then I have to create new column with value ‘1’ in every row labeled ‘open’.

thanks anyway…

Rivo

How about storing the val in the celltag property.

totald = totald + val(CustomersList1.CellTag(row, 6))

If all you’re doing is adding 1 to totald then why do you need to store “1” in the listbox?

 dim row as integer
  dim totald as double
  for row= 0 to CustomersList1.ListCount-1
    if CustomersList1.cell(row,6)="open" then
      totald = totald + 1
    end if
  next
  t_open.text=str(totald)

If I read this right I understand that you have a set of Pairs of values - for example “open” and number (say 25) in say row 1 then “Closed” and 234 (eg) in row 2 etc.

So you could use the Pair method

Here’s a routine to illustrate what I mean (say you have 6 pairs of values)

  Dim P(5) As Pair // Array of 6 Pairs
  Dim I as Integer //just for the loop
  Dim Count As Double=0 // Heres the total
  
  // Set Up test/example Data
  //P.left = string "open" or "Closed"
  //p.right=numeric value of the array
  
  P(0)="Open":25
  P(1)="Closed":234
  P(2)="Open":2533
  P(3)="Open":25
  P(4)="Open":234
  P(5)="Open":2500  
  
  // Populate the list box and total the righthand value of the pair
  // When the lefthand value ="open"
  
  For I= 0 to 5
    listbox1.Addrow Str(P(i).left) // adds lefthand of P to the listbox
    If Listbox1.cell(i,0)="Open" then
       Count = Count +p(i).Right // Counts the total if lefthand of P = "open" getting current count and adding to P.righthandside
    end if
  next I
  // output total
  
  msgbox "Total =:"+str(Count)

To change/input the values in the Pair you cannot use “=” so you’d need to use a constructor like
P(row).Constructor(Listbox1.Cell(row,0),NewValueOfRightHandSide)
(Where row is the row of the listbox to be changed) to change the values contained in the right and left hand side.

Pairs and Dictionarys can be very useful.

Dave nailed it. He seems to just want a count, not a sum.