tags:

views:

1587

answers:

3

I have a form that has 3 text boxes for 3 input values, along with a list box for output. I need the user to be able to input 3 different numbers and click a button to find the average. I'm not really sure how to do/approach this. Any help is greatly appreciated.

Still Stuck....

Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)     
Handles btnAverage.Click
    Dim a As Integer = CInt(txtone.Text)
    Dim b As Integer = CInt(txtTwo.Text)
    Dim c As Integer = CInt(txtThree.Text)
    Dim average As Integer
    average = (a + b + c) / 3
    lstOutput.Text = average
A: 
protected sub on_btn_click()

listbox1.items.add(new listitem((integer.parse(textbox1.text) + integer.parse(textbox2.text) + integer.parse(textbox3.text)) / 3 ))

end sub
Element
while your answer looks correct, I think you should explain it since the OP is admittedly a newbie.
Evan Teran
You're adding items to a list not adding the values.
JaredPar
+2  A: 

Are you unsure about how to convert the input to numbers? If so use the CInt function.

Public Sub OnAverageClick(ByVal sender as Object, ByVal e As EventArgs) Handles AverageButton.Click

    Dim input1 as Integer = CInt(textBox1.Text)
    Dim input2 as Integer = CInt(textBox2.Text)
    Dim input3 as Integer = CInt(textBox3.Text)
    Dim average = (input1 + input2 + input3) / 3

End Sub
JaredPar
Ok now I feel dumb. Thanks for the help!
Davey
I would use Integer.TryParse instead.
Daniel A. White
@Dustin, you are one step closer to true addiction to SO!
JaredPar
A: 

@JaredPar

I would use Integer.TryParse instead.

Daniel A. White
Yes TryParse would be a safer method of doing this.
JaredPar