Dim welcomemessage As String = "QUANTITY DESCRIPTION TOTAL" & vbCr
Dim totalprice As Integer
If Checkbox1.Checked = True Then welcomemessage = TextBox2.Text & vbTab & Checkbox1.Text & (Checkbox1.Text * TextBox2.Text).ToString & vbCr
totalprice = Checkbox1.Text * TextBox2.Text
invalidcastexception was unhandled
Page 1 of 16 Replies - 347 Views - Last Post: 19 July 2012 - 05:11 AM
#1
invalidcastexception was unhandled
Posted 19 July 2012 - 02:15 AM
I've had this error for today and I don't know how to correct it. Would someone please help me? My program would run but it would freeze for sometime
Replies To: invalidcastexception was unhandled
#2
Re: invalidcastexception was unhandled
Posted 19 July 2012 - 02:21 AM
what are you trying to do here?
(Checkbox1.Text * TextBox2.Text).ToString
#3
Re: invalidcastexception was unhandled
Posted 19 July 2012 - 02:22 AM
Look at this line:
What are you doing here? Try to use parsing methods to cast strings to numeric value.
Also look you are taking text of the checkbox1 and do arithmetic with it?!
totalprice = Checkbox1.Text * TextBox2.Text
What are you doing here? Try to use parsing methods to cast strings to numeric value.
Also look you are taking text of the checkbox1 and do arithmetic with it?!
#4
Re: invalidcastexception was unhandled
Posted 19 July 2012 - 02:54 AM
smohd, on 19 July 2012 - 02:22 AM, said:
Look at this line:
What are you doing here? Try to use parsing methods to cast strings to numeric value.
Also look you are taking text of the checkbox1 and do arithmetic with it?!
totalprice = Checkbox1.Text * TextBox2.Text
What are you doing here? Try to use parsing methods to cast strings to numeric value.
Also look you are taking text of the checkbox1 and do arithmetic with it?!
I changed it into
Dim welcomemessage As String = "QUANTITY DESCRIPTION TOTAL" & vbCr
Dim totalprice As Integer
If Checkbox1.Checked = True Then welcomemessage = TextBox2.Text & vbTab & Checkbox1.Text & Str(Val(Checkbox1.Text) & Val(TextBox2.Text)) & vbCr
totalprice = Str(Val(Checkbox1.Text) & Val(TextBox2.Text))
MessageBox.Show(welcomemessage & totalprice)
but it seems that when I place a value on the check box the welcomemessage will change into what I've typed in
#5
Re: invalidcastexception was unhandled
Posted 19 July 2012 - 03:01 AM
That is what you are telling it to do here:
What do you want to do with your code?
welcomemessage = TextBox2.Text & vbTab & Checkbox1.Text &
What do you want to do with your code?
#6
Re: invalidcastexception was unhandled
Posted 19 July 2012 - 04:24 AM
#7
Re: invalidcastexception was unhandled
Posted 19 July 2012 - 05:11 AM
are the 2 other text boxes supposed to be doubles? strings? ints?
total price is int so you have to make the other 2 ints as well and to put it ina message you would put it as totalprice.tostring
total price is int so you have to make the other 2 ints as well and to put it ina message you would put it as totalprice.tostring
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|