@yarbrough40
In a form I have a text box requesting the user to input a number between 1 and 30 as well as a letter p or s. When the button is clicked, depending on if p or s was selected, it should calculate the sum or product of the number from 1 to n. I'm supposed to use functions for the calculations. I've been working on it some more and have the below but it's still not right. Thanks for any advice you might have for me.
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim num As Double
Dim calc As Double
lstAnswer.Items.Clear()
For n As Integer = 1 To 30
num = CDbl(txtNumber.Text)
Next
CalculationS(num, calc)
CalculationP(num, calc)
lstAnswer.Items.Add(num & calc)
End Sub
Function CalculationS(ByVal num As Double, ByVal calc As Double) As Double
If txtLetter.Text = "S" Then
calc = 1 + num
End If
Return calc
lstAnswer.Items.Clear()
End Function
Function CalculationP(ByVal num As Double, ByVal calc As Double) As Double
If txtLetter.Text = "P" Then
calc = 1 * num
End If
Return calc
lstAnswer.Items.Clear()
End Function