This is more of a more elegant issue than functionality. I am looking for an absolutely safe way to check an integer from a string and an object,
Using most of the built-in functions for this in .net seems to throw the first probability exception displayed in the Immediate window, and over time they simply accumulate. what are the consequences of these exceptions, since they do not seem to affect the operation of the system.
Here are my two attempts: both feel awkward, and I know there must be a better way than using VB.IsDBNull and Integer.TryParse ... Or am I just anal.
(integer from the 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
(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
source
share