# Easier way than if/then to find baby weight percentiles?

• ### Question

• Good day All,

I am trying to find the percentile for a child based his/her weight. There will be a lot of data because I will eventually need to include all ages and sex. But, I am starting simple so as to try and understand what I am doing.

I have a datagrid with weight data for a 1 year old male (that I will expand once I understand more)

 Age - years 5%tile 10th %tile 25%tile 50%tile 75%tile 90%tile 1 3 4 5 6 7 8 Etc.

``` 'wt will be child’s actual weightDim wt As Integer
wt = CInt(TextBox1.Text)        If wt >= 4 And wt < 5 Then            '‘msgbox percentile            MsgBox(DataGridView1.Rows(0).Cells(2).Value.ToString)
ElseIf wt >= 5 And wt < 6 Then
MsgBox(DataGridView1.Rows(0).Cells(3).Value.ToString)

'Etc, Etc.
End If```

But, I will end up writing multiple if/then statements, because the age will be all the way up to 18 years. Is there anything easier than writing all of this code, such as "find the closest number in the datagrid" as opposed to if/then statements based on ranges?

Thank you, Mike

Mike

Monday, September 17, 2018 1:40 PM

• Its basically a loop or LINQ statement (e.g. aggregate cell in row.cells where cell.value < userInput select cell.value into max), but where does the actual data come from?

The DataGridView is a display and edit control... it typically isn't the best place to do programmatic analysis.  Your code should ideally be working with the underlying data that the DataGridView is bound to.  You could do a loop or query over the cells in a row as the above pseudo code alludes to, but there may be a better solution, depending on where/how the DataGridView gets its data.

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

• Marked as answer by Monday, September 17, 2018 6:06 PM
Monday, September 17, 2018 1:50 PM

### All replies

• Its basically a loop or LINQ statement (e.g. aggregate cell in row.cells where cell.value < userInput select cell.value into max), but where does the actual data come from?

The DataGridView is a display and edit control... it typically isn't the best place to do programmatic analysis.  Your code should ideally be working with the underlying data that the DataGridView is bound to.  You could do a loop or query over the cells in a row as the above pseudo code alludes to, but there may be a better solution, depending on where/how the DataGridView gets its data.

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

• Marked as answer by Monday, September 17, 2018 6:06 PM
Monday, September 17, 2018 1:50 PM
• "where does the actual data come from"

I was going to enter it into a table or hard code it (but would be a lot of numbers), and then use loop statement

Mike

Monday, September 17, 2018 2:37 PM