213 views

# ListBox - cell data type and column calculation

1. 6 months ago

### Val K

9 Jan 2020 Testers, Xojo Pro

Hi, guys,

I have a ListBox with three columns. The first column contains text, and the other two contain numbers.

How can I:

1. allow only numbers in the the column 2 and column 3
2. calculate the total of all cells in column 2, and in a similar way in column 3

Thank you,

Val

2. ### Dave S

9 Jan 2020 San Diego, California USA

1.... depends on how you are getting the data to the cell... if programmatically then just reject non-numeric values, if user input, modify the keydown of active cell to only accept numeric characters

2. loop thru the cells in each column and add them up... and then it depends on where you want to put the "answer"

3. ### Val K

9 Jan 2020 Testers, Xojo Pro

Got it.

I created a timer and placed this code into it.

```dim sum as double
dim Column as Integer = 0
for row as integer = 0 to ListBox1.ListCount-1
sum = sum + val(ListBox1.cell(row, 1))
next

Label1.Text=str(sum)
```

It loops through the cells and parses the result into the label.

4. ### Stefan A

9 Jan 2020 Testers, Xojo Pro Austria, Tirol
Edited 6 months ago

@Val K Got it.

I created a timer and placed this code into it.

```dim sum as double
dim Column as Integer = 0
for row as integer = 0 to ListBox1.ListCount-1
sum = sum + val(ListBox1.cell(row, 1))
next

Label1.Text=str(sum)
```

It loops through the cells and parses the result into the label.

Better use String.ToDouble instead of Val.

5. ### Val K

9 Jan 2020 Testers, Xojo Pro

Thank you, Stefan.

I will need to wrap my head around it.

Thank you,

Val 