0

Dim agre1, agre2, agre3 As Double
agre1 = Form1.TextBox11.Text
agre2 = Me.TextBox11.Text
agre3 = ((agre1 + agre2) / 2)
TextBox12.Text = agre3

5
Contributors
6
Replies
8
Views
4 Years
Discussion Span
Last Post by tinstaafl
0

The Val Method also works. Also when you display the result back into TextBox12.Text you'll need to use agre3.ToString().

Edited by tinstaafl

0

@deciptikon - quick follow-up question from a dinosaur. What is the difference between CDbl() and Convert.ToDouble(). Is the former being deprecated? Is there a reason why I should prefer one over the other?

1

What is the difference between CDbl() and Convert.ToDouble().

CDbl() is a little smarter by default in that it takes different numbering styles into consideration. You can get a similar effect with Double.Parse() and a formatter of NumberStyles.Any, with the understanding that the extra work has a runtime cost compared to Convert.ToDouble(), where the default behavior uses Double.Parse() with the less thorough NumberStyles.Float and NumberStyles.AllowThousands (if I recall correctly, of course. AllowThousands may not be default).

Ultimately it comes down to whether you want support for currency formatting, slightly more concise syntax, and don't mind depending on the Microsoft.VisualBasic assembly.

0

Use this coding

Dim agre1, agre2, agre3 As Double
agre1 = val(Form1.TextBox11.Text)
agre2 = val(TextBox11.Text)
agre3 = ((agre1 + agre2) / 2)
TextBox12.Text = agre3
1

Implicit conversion are generally not a good idea. Even though Option Strict might be off it's generally a good idea to code like it is on, or to turn it on, and make all your conversion explicit(i.e. TextBox12.Text = agre3.ToString). It can save some confusion down the road.

Edited by tinstaafl

Votes + Comments
Agreed with completely
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.