Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String default parameter value issue after conversion from VB6 to VB.Net

We have a legacy component that has been converted from VB6 to VB.Net.

The VB component was called from an ASPX page using Request("param") to pass optional parameters to function calls. That means the value is null/nothing if the parameter is not present.

The parameters were then added to an ADODB call of a store procedure using Parameters.Append.

When used from VB6 missing, Request("param") values were coerced into empty strings when passed to the VB6 component. This meant that the ADODB call was satisfied (for required parameters).

When the code was ported to VB.Net, the null Request("param") values are now passed as null values (VB nothing?) and Parameters.Append skips adding the value if it is nothing. This caused the stored procedure calls to break as a required param was missing.

My question is:

If we change the component's function parameters to be optional and have paramname as string = "" defaults, will a null/nothing value be converted to an empty string, or is null/nothing treated differently to a parameter being simply missing?

Apologies for the use of the term null, but 99% of my work is C# :)

like image 273
Gone Coding Avatar asked Mar 09 '12 15:03

Gone Coding


1 Answers

If you pass Nothing as the argument for an Optional String parameter that defaults to an empty string, the variable inside the method will have a value of Nothing. It will not have the value of an empty string. They are two different values, because strings in .Net are reference types. You should add code to top of the method to replace Nothing for those parameters with an empty string.

like image 72
Joel Coehoorn Avatar answered Oct 14 '22 02:10

Joel Coehoorn