5

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# :)

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

+15: That was the assumption, thanks for confirming it. I gather that means the default values are nothing more than a complier clue and all parameters are actually passed. We will add the checks instead as you suggest. Thanks
@HiTech exactly, missing params are added at compile-time

Your Answer

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.