# Manage Case Statement with (Int, long, short, double…)

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


## 1 Answer

For value types (i.e. all your types except String) you can use the Convert.ChangeType method:

list.Add(Convert.ChangeType(c.Text, theType))