Hello,
Due to the Format that you are using, if for whatever reason the resulting number is zero, you will get an empty string placed into the TextBox, which I suspect might be part of the problem you are having.
I would suggest that you look into using Double.TryParse to grab your input values, this way you can be sure that what you are getting from the user is valid data. As an example, take a look at this:
In this sample I am simply throwing an exception when something goes wrong, but you would most likely want to handle this a bit more gracefully.Code:Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click 'CURRENT FIXTURE part 1 Dim a As Double Dim b As Double Dim c As Double Dim d As Double If Not Double.TryParse(TextBox1.Text, a) Then Throw New ArgumentException("Unable to validate the Light Wattage Input") End If If Not Double.TryParse(TextBox2.Text, b) Then Throw New ArgumentException("Unable to validate the QTY Input") End If If Not Double.TryParse(TextBox3.Text, c) Then Throw New ArgumentException("Unable to validate the Operation Time Input") End If Dim annualKw As Double = a * b * c * 365 TextBox4.Text = Format(annualKw, "#,###,") If Not Double.TryParse(TextBox5.Text, d) Then Throw New ArgumentException("Unable to validate the charge per kw Input") End If 'CURRENT FIXTURE part 2 'Multiply the annual Kw usage * kw charged Dim annualCost As Integer = annualKw * d TextBox6.Text = Format(annualCost, "#,###,") End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click MsgBox("yay") End Sub End Class
Hope that helps!
Gary





Reply With Quote