By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

Function Return Statement Always Returns 0?

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

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Dim currentValue As String
  4.     Dim dblCurrentValue As Double
  5.     Dim newValue As Double
  6.     Dim dblOldValue As Double
  7.  
  8.     Private Function GetBonus(ByRef dblOldValue) As Double
  9.         Dim dblNewValue As Double
  10.         dblNewValue = dblOldValue * 1.1
  11.         Return dblNewValue
  12.  
  13.     End Function
  14.  
  15.     Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
  16.         txtBox.Text = currentValue
  17.         Double.TryParse(currentValue, dblCurrentValue)
  18.  
  19.         newValue = GetBonus(dblCurrentValue)
  20.         txtBox.Text = newValue.ToString()
  21.     End Sub
  22. 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!
Mar 19 '14 #1

✓ answered by Rabbit

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.

Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,366
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.
Mar 20 '14 #2

P: 6
thank you so much! Sorry i didnt know their were code tags
Mar 20 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.