This is probally more of an elegance question than functionality. I am looking for the absolutely safest way to check for an integer from a string and an object,
Using most of the built in functions for this in .net seem to generate a first chance exception, displayed in the Immediate window, and over time they just build up. what are the implications of these exceptions as they don't seem to affect the operation of the system.
Here are my two attempts, both feel clunky and I know there has to be a better way than using VB.IsDBNull and Integer.TryParse... Or am I just being anal.
(to integer from object)
Dim nInteger As Integer = 0 If oData Is Nothing OrElse VB.IsDBNull(oData) Then Else If bThrowErrorIfInvalid Then Else On Error Resume Next End If nInteger = CType(oData, Integer) End If Return nInteger
(to integer from string)
Dim nInteger As Integer = 0 If sText Is Nothing Then Else If bThrowErrorIfInvalid Then Else On Error Resume Next End If Integer.TryParse(sText, nInteger) End If Return nInteger