Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

I Need Help Please (asap)

louzhouselouzhouse Member Posts: 6
I'm having problems with the function procedure. I want to use the result of the function calories in textbox4.text
Where is the value of the function calories stored and how to I get it over to the textbox. I don't know if I might have mistakes in the rest of the code. Thanks for any help.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim carb, fat, protein As Double
carb = CDbl(TextBox1.Text)
fat = CDbl(TextBox2.Text)
protein = CDbl(TextBox3.Text)
inputgrams(carb, fat, protein)
showcalories(carb, fat, protein)
TextBox4.Text = ("The serving contains " & _
(I Need Function Calories Here)&" calories")

End Sub
Sub inputgrams(ByVal c As Double, ByVal f As Double, ByVal p As Double)
End Sub
Function calories(ByRef c As Double, ByRef f As Double, _
ByRef p As Double) As Double
Dim carb, fat, protein As Double
carb = c * 4
fat = f * 9
protein = p * 4
Return carb + fat + protein
End Function
Sub showcalories(ByRef carb As Double, ByRef fat As Double, ByRef protein As Double)
End Sub
End Class

Comments

  • DjSpiritDjSpirit Member Posts: 371
    [grey]For starters I suggest that you stop using Subprocedures and start using Functions. Subprocedures don't return anything, Functions does:
    [code]Function CalcCalories(ByVal carb As Double, ByVal fat As Double, ByVal protein As Double) As String
    Dim Calories As Double

    '-- Stuff your calculations here

    Return Calories
    End Function[/code]

    If you do this you can set the text like this:
    [code]TextBox4.Text = "The serving contains " & CalcCalories(carb, fat, protein).ToString() & " calories."[/code]

    DjSpirit.com, somewhat .net compatible[/grey]

    : I'm having problems with the function procedure. I want to use the result of the function calories in textbox4.text
    : Where is the value of the function calories stored and how to I get it over to the textbox. I don't know if I might have mistakes in the rest of the code. Thanks for any help.
    :
    : Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    : Dim carb, fat, protein As Double
    : carb = CDbl(TextBox1.Text)
    : fat = CDbl(TextBox2.Text)
    : protein = CDbl(TextBox3.Text)
    : inputgrams(carb, fat, protein)
    : showcalories(carb, fat, protein)
    : TextBox4.Text = ("The serving contains " & _
    : (I Need Function Calories Here)&" calories")
    :
    : End Sub
    : Sub inputgrams(ByVal c As Double, ByVal f As Double, ByVal p As Double)
    : End Sub
    : Function calories(ByRef c As Double, ByRef f As Double, _
    : ByRef p As Double) As Double
    : Dim carb, fat, protein As Double
    : carb = c * 4
    : fat = f * 9
    : protein = p * 4
    : Return carb + fat + protein
    : End Function
    : Sub showcalories(ByRef carb As Double, ByRef fat As Double, ByRef protein As Double)
    : End Sub
    : End Class
    :
    :

Sign In or Register to comment.