Use of Null/IsNull() detected.
In Visual Basic 6.0, the Null keyword indicated that a field contained no valid data, and the IsNull function was used to test for Null. In addition, Visual Basic 6 supported Null propagation when Null was used in an expression, the result of the expression would also be Null. For a more thorough discussion of data types in Visual Basic please refer to the Data Type documentation.
In Visual Basic .NET, the Null keyword is still a reserved word, but it has no syntactical value, and the IsNull function is no longer supported.
C# also reserves the null keyword, but it is not to be confused with Null in Visual Basic 6. Visual Basic's Null keyword indicated missing or invalid data in data field, which is the purpose of DbNull in the .Net Framework. C#'s version of null is closer to Visual Basic 6's Nothing keyword.
Also, Null propagation is no longer supported in the .NET framework. When upgrading Visual Basic 6 applications avoid null propagation.
During upgrade, Null is converted to DBNull, and IsNull is converted to IsDBNull of which there are several variants: Visual Basic's IsDBNull function, the Convert.IsDBNull method, the DataTableReader.IsDBNull method, and the IDataRecord.IsDBNull method).
The behavior of DBNull is slightly different than that of Null. Null could be used in functions and assignments as a Variant data type, however DBNull is a class and thus cannot be used as a direct replacement for Visual Basic's Null, DBNull.Value however can be passed as a value type in methods or assignments.
Where Null was used with a Variant data type, the Variant is converted to Object during upgrade; in these cases, depending on context, it may be more appropriate to use the Nothing and the IsNothing function for VB.Net. For C# use the null keyword and compare with null with the equality operators (== and !=).
Code that uses Null propagation requires considerable work in either the migrated version or the original VB6 code to remove such propagation.
One approach if the affected code is small is to preface it with an If statement checking for DBNull values, as done in the sample code. Another approach if using a typed DataSet is to take advantage of the built-in IsFieldNameNull() methods to determine if a particular field is set to DBNull.Value. Alternatively, one may use the IsNull() method for DataRows to test if a particular field is DBNull.
Another approach is to create a function that wraps this logic. That's the approach taken with the ResultTxt function which handles the output of DBNulls for us (as well as the display of strings with quotes around them).
In this example, the input sample was limited and given C# strong-type nature we're forced to contemplate many more scenarios in code than with Visual Basic.Net's more dynamic typing. In the solution for this sample reduced the input types to System.Int32 to keep code brief.
Additionally, two methods were created VbLeft and VbMid to replicate the behavior of the original VB functions. The reason for doing this is because the String.Substring is much more stringent about the parameters it takes and bound checks them, throwing an exception if any of them are out of bounds. Visual Basic 6 automatically handled these out of range cases.
C#'s behavior is helpful though in highlighting possible problem areas. So another solution might involve dynamically changing the trim size based on the input. In this case C#'s strongly-type system require we pay more attention to the intent of the code and fix it accordingly.