\$\begingroup\$
\$\endgroup\$
I have the following case statements that has to be modified to fit these cases:
Dec
, Double
, Int
, Long
, Short
, Date
, and String
.
Please let me know if there is an easier way to handle this rather than repeating the following (slightly modified for each case):
Case GetType(Integer)
If String.IsNullOrEmpty(c.Text) Then
list.Add(CInt(0))
Else
Try
list.Add(CInt(c.Text))
Catch ex As Exception
WriteAudit(ex, True)
Dim intValue As Integer
If Not Integer.TryParse(c.Text, intValue) Then
c.Text = c.Text.Substring(0, c.Text.Length - 1)
MessageBox.Show("Please Enter Only Integer Values Here")
End If
End Try
End If
Pimgd
22.5k5 gold badges68 silver badges144 bronze badges
1 Answer 1
\$\begingroup\$
\$\endgroup\$
0
For value types (i.e. all your types except String
) you can use the Convert.ChangeType
method:
list.Add(Convert.ChangeType(c.Text, theType))
answered Aug 13, 2013 at 18:38
lang-vb