so have button reads file, , puts contents of file list box. when press button shows:
jim 6 8 9
tim 7 5 6
bill 4 10 8
what want make separate button adds each of person's scores , finds average of them. once has calculated average of person want average in place of 3 scores.
the code have @ moment takes first score of each person , adds of them , shows result in messagebox.
this code @ moment:
dim scorevalues new list(of integer) each line string in system.io.file.readlines(file1) dim scores system.text.regularexpressions.match = system.text.regularexpressions.regex.match(line, "\d+") if scores.success scorevalues.add(convert.toint32(scores.value)) end if next listbox1.datasource = scorevalues dim scoretots integer = 0 scores2 = 0 listbox1.items.count - 1 scoretots = scoretots + listbox.items(scores2) next messagebox.show("total: " & scoretots.tostring)
this code produces:
6
7
4
and messagebox shows 28
this going. it's same question https://stackoverflow.com/questions/29902255/working-out-averages-of-numbers-in-a-list-box-line/29902583#29902583
sub main() dim scores string = "bill 10 9 8" dim score system.text.regularexpressions.matchcollection = system.text.regularexpressions.regex.matches(scores, "\d+") dim sum integer = 0 integer = 0 score.count - 1 sum += convert.toint32(score.item(i).value) console.writeline(score.item(i).value) next dim average = sum / score.count console.writeline("average: {0}", average) console.readline() end sub
results: