Function Return Statement Always Returns 0?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IsaiahMatz
    New Member
    • Mar 2014
    • 6

    #1

    Function Return Statement Always Returns 0?

    Ok so here is my code(i apologize if some of the code wrapped around)

    Code:
    Public Class Form1
    
        Dim currentValue As String
        Dim dblCurrentValue As Double
        Dim newValue As Double
        Dim dblOldValue As Double
    
        Private Function GetBonus(ByRef dblOldValue) As Double
            Dim dblNewValue As Double
            dblNewValue = dblOldValue * 1.1
            Return dblNewValue
    
        End Function
    
        Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
            txtBox.Text = currentValue
            Double.TryParse(currentValue, dblCurrentValue)
    
            newValue = GetBonus(dblCurrentValue)
            txtBox.Text = newValue.ToString()
        End Sub
    End Class
    My question is, why is it that no matter what number i try to calculate, the end result is a zero? Im really new to this and im completely stumped. Thanks!
    Last edited by Rabbit; Mar 20 '14, 03:18 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    Line 16 should be flipped. You are currently assigning a blank string to the textbox. If you try to parse that, a blank string will be parsed as 0.

    Comment

    • IsaiahMatz
      New Member
      • Mar 2014
      • 6

      #3
      thank you so much! Sorry i didnt know their were code tags

      Comment

      Working...