I have a form where a person can select how many of a product they want
e.g. 1x2g Syringe, 15x100g jar etc. The code will then display string
output in a label, listing the products that have a quanitity of
greater than 0. This works fine. Now what I wanted to do is that each
time a quanitity text box is changed the form would refresh the string
output. I have done this by calling the procedure (which outputs the
string output) many times for each quantity box's EventChanged event
Here's the procedure which outputs the string output (there are many
more 'gram' variables but they're all similar so i didn't include
them):
Public Sub PackingOutput()
Dim totalgram As String
Dim gram2 As String
Dim gram5 As String
Dim gram10 As String
Dim num_txt2g As Integer
Dim num_txt5g As Integer
Dim num_txt10g As Integer
num_txt2g = CInt(txt2g.Text)
If num_txt2g > 0 Then
gram2 = num_txt2g & " " & lbl2g.Text & ", "
End If
num_txt5g = CInt(txt5g.Text)
If num_txt5g > 0 Then
gram5 = num_txt5g & " " & lbl5g.Text & ", "
End If
num_txt10g = CInt(txt10g.Text)
If num_txt10g > 0 Then
gram10 = num_txt10g & " " & lbl10g.Text & ", "
End If
totalgram = gram2 & gram5 & gram10
lblPackingOutput2.Text = totalgram
And here's an example of the EventChanged events:
Private Sub txt2g_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles txt2g.TextChanged
Call PackingOutput()
End Sub
Private Sub txt5g_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles txt5g.TextChanged
Call PackingOutput()
End Sub
Private Sub txt10g_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles txt10g.TextChanged
Call PackingOutput()
End Sub
The problem is when I just have txt2g_TextChanged it works fine, but if
I have more than one sub calling the same procedure I get "an unhandled
exception of type 'System.InvalidCastException' occurred in
microsoft.visualbasic.dll. Addition information: Cast from string "" to
type 'Integer' is not valid"
Anyone know how to fix?