.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

calculation pblm

Posted By: vidhya     Posted Date: November 02, 2010    Points:2   Category :VB.Net
Dim t1 As Double, t2 As Double, t As Double
t1 = Convert.ToDouble(textBox3.Text)
t2 = Convert.ToDouble(textBox4.Text)

t = Math.Round((t1 + t2) / 2)

textBox5.Text = t.ToString()

in this code i put t1,t2 values the op was shown,bt i put t1 value and t2 value is empty the calculation is not working ,,Input string was not in a correct format.error wil accure ,in case i giv t1 value onlu how to get t3

if i set deflt value0 ,the o/p is shown 0+70/2=35 not show in 70

Author: Dhivakaran             
Posted Date: November 02, 2010     Points: 5   

Hi Vidhya,

you can use the below code..

Dim t1 As Double, t2 As Double, t As Double
If String.IsNullOrEmpty(TextBox1.Text) Then
t1 = 0
t1 = Convert.ToDouble(TextBox1.Text)
End If
If String.IsNullOrEmpty(TextBox2.Text) Then
t2 = 0
t2 = Convert.ToDouble(TextBox2.Text)
End If
t = Math.Round((t1 + t2) / 2)
TextBox3.Text = t.ToString()

Dhivakaran T
Author: ASPEvil             
Posted Date: November 03, 2010     Points: 5   

Set the "Text" property of "textbox3" and "textbox4" to "0" (zero). So, whenever you will not have anything to insert in any of these textbox controls, then default zero will be taken or else you have to insert other values erasing the zeros.

This type of error is being generated as there is nothing mentioned as the default value and whenever you are not inserting any value in any of these textboxes then just the NULL value is being taken and the system then trying to convert this NULL value to Double, which is meaningless and impossible.

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend