I've exhausted every possible way I can think of to do this and I keep receiving this error:
"Input string was not in a correct format." Source Error:
Line 75: Dim intChocolate As Integer
Line 76: Dim strChocolate As String = txtChocolate.Text
Line 77: intChocolate = Convert.ToInt32(strChocolate) <----------HiLighted Red!!
Line 78:
Line 79: Dim intRaspberry As Integer
So what my program is is a "Checkout Page" .aspx web page with several textboxes for quantities of donuts at various prices ($1, $2, $3). The page has 1 calculate button that is supposed to run a ".aspx.vb" code segment to read those textbox.text properties, store them to a string, and then Convert.ToInt32. Those integers will be stored, multiplied by their prices, and a Total Cost will be displayed on the page.
The ONLY problem I am having with this is simply getting that textbox.text string to convert to an integer.
My .aspx.vb code:
Protected Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim gPrice As Decimal
gPrice = 1
Dim cPrice As Decimal
cPrice = 1.5
Dim rPrice As Decimal
rPrice = 2
Dim regPrice As Decimal
regPrice = 1
Dim iPrice As Decimal
iPrice = 1.5
Dim mPrice As Decimal
mPrice = 2
Dim intGlazed As Integer
Dim strGlazed As String = txtGlazed.Text
intGlazed = Convert.ToInt32(strGlazed)
Dim intChocolate As Integer
Dim strChocolate As String = txtChocolate.Text
intChocolate = Convert.ToInt32(strChocolate)
Dim intRaspberry As Integer
Dim strRaspberry As String = txtRaspberry.Text
intRaspberry = Convert.ToInt32(strRaspberry)
Dim intRegular As Integer
Dim strRegular As String = txtRegular.Text
intRegular = Convert.ToInt32(strRegular)
Dim intIced As Integer
Dim strIced As String = txtIced.Text
intIced = Convert.ToInt32(strIced)
Dim intMocha As Integer
Dim strMocha As String = txtMocha.Text
intMocha = Convert.ToInt32(strMocha)
txtSubtotal.Text = calc.CalculateSubtotal(intGlazed, intChocolate, intRaspberry, intRegular, intIced, intMocha, gPrice, cPrice, rPrice, regPrice, iPrice, mPrice)
I'm sure this is some conflict in the way that Strings/Integers or textbox.text properties are handled in VB vs .aspx, but I can't for the life of me figure out why I am getting this error.
Any help is greatly appreciated, thank you very much.
txtChocolate.Text
is empty or it's not a number? – ekad