0
\$\begingroup\$

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
asked Aug 13, 2013 at 15:34
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.