VBScript Null Session Variable String Comparison

Environment: ASP, IIS, server-side VBScript
Problem: A string comparison where I compared a Session variable to a form field would return a "strings are equal" type of result when the Session variable was null and the form field value was a non-null string. The logic I used was initially:

IF Session("myVar") <> Request.Form("my_var") THEN
' no match
ELSE
' strings matched
END IF

I replaced the IF condition like this:

IF (StrComp(Session("myVar"), Request.Form("my_var")) <> 0) THEN

but it still returned a string match when the Session variable was null and the form field value was a non-null string.

The Fix: I forced the Session variable into a string-type page-level variable, like this:

session_myVar = "" & Session("myVar")

I then used session_myVar in the comparisons instead of using the Session variable directly.

 

Database Normalization Explained
50-page eBook shares nearly 30 years of business experience with data modeling for government, industrial, communications and other large relational database customers.

 

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.